~ubuntu-branches/ubuntu/vivid/openipmi/vivid

« back to all changes in this revision

Viewing changes to lib/lanparm.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2006-09-15 17:56:24 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060915175624-ljk0mg3xtcm65tvm
Tags: 2.0.7-1
* new upstream release from 2006-06-08
  Thanks to John Wright <john.wright hp.com> for initial work
  (closes: Bug#380149)
* updated Standards Version
* new binaries openipmicmd, openipmish, rmcp_ping

Show diffs side-by-side

added added

removed removed

Lines of Context:
558
558
    return;
559
559
}
560
560
 
561
 
static void
 
561
static int
562
562
start_config_fetch(void *cb_data, int shutdown)
563
563
{
564
564
    lanparm_fetch_handler_t *elem = cb_data;
570
570
                 "LANPARM was destroyed while an operation was in progress");
571
571
        lanparm_lock(elem->lanparm);
572
572
        fetch_complete(elem->lanparm, ECANCELED, elem);
573
 
        return;
 
573
        return OPQ_HANDLER_STARTED;
574
574
    }
575
575
 
576
576
    /* The read lock must be claimed before the lanparm lock to avoid
583
583
        lanparm_lock(elem->lanparm);
584
584
        fetch_complete(elem->lanparm, rv, elem);
585
585
    }
 
586
    return OPQ_HANDLER_STARTED;
586
587
}
587
588
 
588
589
int
721
722
    return;
722
723
}
723
724
 
724
 
static void
 
725
static int
725
726
start_config_set(void *cb_data, int shutdown)
726
727
{
727
728
    lanparm_set_handler_t *elem = cb_data;
733
734
                 "LANPARM was destroyed while an operation was in progress");
734
735
        lanparm_lock(elem->lanparm);
735
736
        set_complete(elem->lanparm, ECANCELED, elem);
736
 
        return;
 
737
        return OPQ_HANDLER_STARTED;
737
738
    }
738
739
 
739
740
    /* The read lock must be claimed before the lanparm lock to avoid
746
747
        lanparm_lock(elem->lanparm);
747
748
        set_complete(elem->lanparm, rv, elem);
748
749
    }
 
750
    return OPQ_HANDLER_STARTED;
749
751
}
750
752
 
751
753
int
881
883
 
882
884
    unsigned char  num_cipher_suites;
883
885
    unsigned char  cipher_suite_entries[16];
 
886
    unsigned char  max_priv_for_cipher_suite_supported;
884
887
    unsigned char  max_priv_for_cipher_suite[16];
885
888
 
886
889
    unsigned char num_alert_destinations;
914
917
        opt = ((unsigned char *) lanc) + lp->optional_offset;
915
918
 
916
919
    if (err) {
917
 
        if (opt && (err == IPMI_IPMI_ERR_VAL(0x80))) {
 
920
        if (opt
 
921
            && ((err == IPMI_IPMI_ERR_VAL(0x80))
 
922
                /* Some systems incorrectly return 0xcc.  Sigh. */
 
923
                || (err == IPMI_IPMI_ERR_VAL(0xcc))))
 
924
        {
918
925
            *opt = 0;
919
926
            return 0;
920
927
        }
998
1005
        opt = ((unsigned char *) lanc) + lp->optional_offset;
999
1006
 
1000
1007
    if (err) {
1001
 
        if (opt && (err == IPMI_IPMI_ERR_VAL(0x80))) {
 
1008
        if (opt
 
1009
            && ((err == IPMI_IPMI_ERR_VAL(0x80))
 
1010
                /* Some systems incorrectly return 0xcc.  Sigh. */
 
1011
                || (err == IPMI_IPMI_ERR_VAL(0xcc))))
 
1012
        {
1002
1013
            *opt = 0;
1003
1014
            return 0;
1004
1015
        }
1034
1045
        opt = ((unsigned char *) lanc) + lp->optional_offset;
1035
1046
 
1036
1047
    if (err) {
1037
 
        if (opt && (err == IPMI_IPMI_ERR_VAL(0x80))) {
 
1048
        if (opt
 
1049
            && ((err == IPMI_IPMI_ERR_VAL(0x80))
 
1050
                /* Some systems incorrectly return 0xcc.  Sigh. */
 
1051
                || (err == IPMI_IPMI_ERR_VAL(0xcc))))
 
1052
 
 
1053
        {
1038
1054
            *opt = 0;
1039
1055
            return 0;
1040
1056
        }
1106
1122
 
1107
1123
    data++; /* Skip over the revision byte. */
1108
1124
 
1109
 
    sel = data[0] & 0xf;
 
1125
    if ((data[0] & 0xf) != lanc->curr_sel) {
 
1126
        /* Yikes, wrong selector came back! */
 
1127
        ipmi_log(IPMI_LOG_WARNING,
 
1128
                 "lanparm.c(got_parm): "
 
1129
                 "Error fetching dest type %d,"
 
1130
                 " wrong selector came back, expecting %d, was %d."
 
1131
                 "  Assuming it is %d.",
 
1132
                 lanc->curr_parm, lanc->curr_sel, data[0] & 0xf,
 
1133
                 lanc->curr_sel);
 
1134
    }
 
1135
 
 
1136
    sel = lanc->curr_sel;
1110
1137
    if (sel > lanc->num_alert_destinations)
1111
1138
        return 0; /* Another error check will get this later. */
1112
1139
 
1145
1172
 
1146
1173
    data++; /* Skip over the revision byte. */
1147
1174
 
1148
 
    sel = data[0] & 0xf;
 
1175
    if ((data[0] & 0xf) != lanc->curr_sel) {
 
1176
        /* Yikes, wrong selector came back! */
 
1177
        ipmi_log(IPMI_LOG_ERR_INFO,
 
1178
                 "lanparm.c(got_parm): "
 
1179
                 "Error fetching dest addr %d,"
 
1180
                 " wrong selector came back, expecting %d, was %d."
 
1181
                 "  Assuming it is %d.",
 
1182
                 lanc->curr_parm, lanc->curr_sel, data[0] & 0xf,
 
1183
                 lanc->curr_sel);
 
1184
    }
 
1185
 
 
1186
    sel = lanc->curr_sel;
1149
1187
    if (sel > lanc->num_alert_destinations)
1150
1188
        return 0; /* Another error check will get this later. */
1151
1189
 
1268
1306
static int gcp(ipmi_lan_config_t *lanc, lanparms_t *lp, int err,
1269
1307
               unsigned char *data)
1270
1308
{
1271
 
    int i, j;
 
1309
    unsigned char *opt;
 
1310
    int           i, j;
1272
1311
 
1273
 
    if (err)
 
1312
    opt = ((unsigned char *) lanc) + lp->optional_offset;
 
1313
    if (err) {
 
1314
        if (err == IPMI_IPMI_ERR_VAL(0x80)) {
 
1315
            *opt = 0;
 
1316
            return 0;
 
1317
        }
1274
1318
        return err;
 
1319
    }
 
1320
 
 
1321
    if (opt)
 
1322
        *opt = 1;
1275
1323
 
1276
1324
    data++; /* Skip over the revision byte. */
1277
1325
    data++; /* Skip over reserved byte */
1416
1464
    { 1, S, 1, 0, gvp, svp   }, /* IPMI_LANPARM_VLAN_PRIORITY                */
1417
1465
    { 1, 0, 1, 0, gnc, NULL  }, /* IPMI_LANPARM_NUM_CIPHER_SUITE_ENTRIES     */
1418
1466
    { 1, 0, 17, 0, gcs, NULL }, /* IPMI_LANPARM_CIPHER_SUITE_ENTRY_SUPPORT   */
1419
 
    { 1, 0, 9, 0, gcp, scp   }, /* IPMI_LANPARM_CIPHER_SUITE_ENTRY_PRIV      */
 
1467
#undef S
 
1468
#define S OFFSET_OF(max_priv_for_cipher_suite_supported)
 
1469
    { 1, S, 9, 0, gcp, scp   }, /* IPMI_LANPARM_CIPHER_SUITE_ENTRY_PRIV      */
1420
1470
#undef S
1421
1471
#define S OFFSET_OF(vlan_tag_supported)
1422
1472
    { 1, S, 4, 0, gvt, svt   }, /* IPMI_LANPARM_DEST_VLAN_TAG                */
1447
1497
    lanparms_t        *lp = &(lanparms[lanc->curr_parm]);
1448
1498
 
1449
1499
    /* Check the length, and don't forget the revision byte must be added. */
1450
 
    if ((!err) && (data_len < (lp->length+1))) {
 
1500
    if ((!err) && (data_len < (unsigned int) (lp->length+1))) {
1451
1501
        if ((data_len == 1) && (lp->optional_offset)) {
1452
1502
            /* Some systems return zero-length data for optional parms. */
1453
1503
            unsigned char *opt = ((unsigned char *)lanc) + lp->optional_offset;
1483
1533
        break;
1484
1534
 
1485
1535
    case IPMI_LANPARM_DEST_TYPE:
1486
 
        if ((data[1] & 0xf) != lanc->curr_sel) {
1487
 
            /* Yikes, wrong selector came back! */
1488
 
            ipmi_log(IPMI_LOG_ERR_INFO,
1489
 
                     "lanparm.c(got_parm): "
1490
 
                     "Error fetching dest type %d,"
1491
 
                     " wrong selector came back, expecting %d, was %d",
1492
 
                     lanc->curr_parm, lanc->curr_sel, data[1] & 0xf);
1493
 
            err = EINVAL;
1494
 
            goto done;
1495
 
        }
1496
1536
        lanc->curr_sel++;
1497
1537
        if (lanc->curr_sel >= lanc->num_alert_destinations) {
1498
1538
            lanc->curr_parm++;
1501
1541
        break;
1502
1542
 
1503
1543
    case IPMI_LANPARM_DEST_ADDR:
1504
 
        if ((data[1] & 0xf) != lanc->curr_sel) {
1505
 
            /* Yikes, wrong selector came back! */
1506
 
            ipmi_log(IPMI_LOG_ERR_INFO,
1507
 
                     "lanparm.c(got_parm): "
1508
 
                     "Error fetching dest addr %d,"
1509
 
                     " wrong selector came back, expecting %d, was %d",
1510
 
                     lanc->curr_parm, lanc->curr_sel, data[1] & 0xf);
1511
 
            err = EINVAL;
1512
 
            goto done;
1513
 
        }
1514
1544
        lanc->curr_sel++;
1515
1545
        if (lanc->curr_sel >= lanc->num_alert_destinations) {
1516
1546
            lanc->curr_parm = IPMI_LANPARM_VLAN_ID;
1848
1878
                    void                 *cb_data)
1849
1879
{
1850
1880
    ipmi_lan_config_t *lanc;
1851
 
    unsigned char     data[1];
 
1881
    unsigned char     data[MAX_IPMI_DATA_SIZE];
1852
1882
    lanparms_t        *lp;
1853
1883
    int               rv;
1854
1884
 
2311
2341
                                      unsigned int      entry,
2312
2342
                                      unsigned int      val)
2313
2343
{
 
2344
    if (! lanc->max_priv_for_cipher_suite_supported)
 
2345
        return ENOSYS;
2314
2346
    if (entry >= lanc->num_cipher_suites)
2315
2347
        return EINVAL;
2316
2348
    lanc->cipher_suite_entries[entry] = val;
2322
2354
                                             unsigned int      entry,
2323
2355
                                             unsigned int      *val)
2324
2356
{
 
2357
    if (! lanc->max_priv_for_cipher_suite_supported)
 
2358
        return ENOSYS;
2325
2359
    if (entry >= lanc->num_cipher_suites)
2326
2360
        return EINVAL;
2327
2361
    *val = lanc->max_priv_for_cipher_suite[entry];
2343
2377
typedef struct lanparm_gendata_s
2344
2378
{
2345
2379
    enum ipmi_lanconf_val_type_e datatype;
2346
 
    unsigned char *fname;
 
2380
    char *fname;
2347
2381
 
2348
2382
    union {
2349
2383
        struct {
2370
2404
    unsigned int (*iv_cnt)(ipmi_lan_config_t *lanc);
2371
2405
} lanparm_gendata_t;
2372
2406
 
2373
 
unsigned int ret_user_cnt(ipmi_lan_config_t *lanc)
 
2407
static unsigned int ret_user_cnt(ipmi_lan_config_t *lanc)
2374
2408
{
2375
2409
    return 5;
2376
2410
}
2434
2468
    F_BOOLR(support_auth_md2),
2435
2469
    F_BOOLR(support_auth_none),
2436
2470
    F_INT(ip_addr_source),                              /* 5 */
2437
 
    F_INTR(num_alert_destinations),
2438
2471
    F_INTV(ipv4_ttl),
2439
2472
    F_INTV(ipv4_flags),
2440
2473
    F_INTV(ipv4_precedence),
2441
 
    F_INTV(ipv4_tos),                                   /* 10 */
2442
 
    F_BOOLIV(enable_auth_oem, ret_user_cnt),
 
2474
    F_INTV(ipv4_tos),
 
2475
    F_BOOLIV(enable_auth_oem, ret_user_cnt),            /* 10 */
2443
2476
    F_BOOLIV(enable_auth_straight, ret_user_cnt),
2444
2477
    F_BOOLIV(enable_auth_md5, ret_user_cnt),
2445
2478
    F_BOOLIV(enable_auth_md2, ret_user_cnt),
2446
 
    F_BOOLIV(enable_auth_none, ret_user_cnt),           /* 15 */
2447
 
    F_IP(ip_addr),
 
2479
    F_BOOLIV(enable_auth_none, ret_user_cnt),
 
2480
    F_IP(ip_addr),                                      /* 15 */
2448
2481
    F_MAC(mac_addr),
2449
2482
    F_IP(subnet_mask),
2450
2483
    F_INTV(port_rmcp_primary),
2451
 
    F_INTV(port_rmcp_secondary),                        /* 20 */
2452
 
    F_BOOLV(bmc_generated_arps),
 
2484
    F_INTV(port_rmcp_secondary),
 
2485
    F_BOOLV(bmc_generated_arps),                        /* 20 */
2453
2486
    F_BOOLV(bmc_generated_garps),
2454
2487
    F_INTV(garp_interval),
2455
2488
    F_IP(default_gateway_ip_addr),
2456
 
    F_MAC(default_gateway_mac_addr),                    /* 25 */
2457
 
    F_IP(backup_gateway_ip_addr),
 
2489
    F_MAC(default_gateway_mac_addr),
 
2490
    F_IP(backup_gateway_ip_addr),                       /* 25 */
2458
2491
    F_MAC(backup_gateway_mac_addr),
2459
2492
    F_DATA(community_string),
 
2493
    F_INTR(num_alert_destinations),
2460
2494
    F_BOOLIV(alert_ack, ipmi_lanconfig_get_num_alert_destinations),
2461
2495
    F_INTIV(dest_type, ipmi_lanconfig_get_num_alert_destinations), /* 30 */
2462
2496
    F_INTIV(alert_retry_interval, ipmi_lanconfig_get_num_alert_destinations),
2477
2511
#define NUM_GDATA_ENTRIES (sizeof(gdata) / sizeof(lanparm_gendata_t))
2478
2512
 
2479
2513
int
 
2514
ipmi_lanconfig_enum_val(unsigned int parm, int val, int *nval,
 
2515
                        const char **sval)
 
2516
{
 
2517
    char *rval;
 
2518
    int  rnval;
 
2519
    if (parm == 5) { /* ip_addr_source */
 
2520
        if (val < 0) {
 
2521
            if (nval)
 
2522
                *nval = 0;
 
2523
            return EINVAL;
 
2524
        }
 
2525
        switch (val) {
 
2526
        case 0:
 
2527
            rval = "unspecified";
 
2528
            rnval = 1;
 
2529
            break;
 
2530
        case 1:
 
2531
            rval = "manually configured";
 
2532
            rnval = 2;
 
2533
            break;
 
2534
        case 2:
 
2535
            rval = "DHCP";
 
2536
            rnval = 3;
 
2537
            break;
 
2538
        case 3:
 
2539
            rval = "BIOS configured";
 
2540
            rnval = 4;
 
2541
            break;
 
2542
        case 4:
 
2543
            rval = "other protocol";
 
2544
            rnval = -1;
 
2545
            break;
 
2546
        default:
 
2547
            if (*nval)
 
2548
                *nval = -1;
 
2549
            return EINVAL;
 
2550
        }
 
2551
    } else if (parm == 43) { /* cipher_suite_entry */
 
2552
        if (val < 0) {
 
2553
            if (nval)
 
2554
                *nval = 0;
 
2555
            return EINVAL;
 
2556
        }
 
2557
        switch (val) {
 
2558
        case 0: rval = "RAKP-none,none,none"; rnval = 1; break;
 
2559
        case 1: rval = "RAKP-HMAC-SHA1,none,none"; rnval = 2; break;
 
2560
        case 2: rval = "RAKP-HMAC-SHA1,HMAC-SHA1-96,none"; rnval = 3; break;
 
2561
        case 3: rval = "RAKP-HMAC-SHA1,HMAC-SHA1-96,AES-CBC-128"; rnval = 4; break;
 
2562
        case 4: rval = "RAKP-HMAC-SHA1,HMAC-SHA1-96,xRC4-128"; rnval = 5; break;
 
2563
        case 5: rval = "RAKP-HMAC-SHA1,HMAC-SHA1-96,xRC4-40"; rnval = 6; break;
 
2564
        case 6: rval = "RAKP-HMAC-MD5,none,none"; rnval = 7; break;
 
2565
        case 7: rval = "RAKP-HMAC-MD5,HMAC-MD5-128,none"; rnval = 8; break;
 
2566
        case 8: rval = "RAKP-HMAC-MD5,HMAC-MD5-128,AES-CBC-128"; rnval = 9; break;
 
2567
        case 9: rval = "RAKP-HMAC-MD5,HMAC-MD5-128,xRC4-128"; rnval = 10; break;
 
2568
        case 10: rval = "RAKP-HMAC-MD5,HMAC-MD5-128,xRC4-40"; rnval = 11; break;
 
2569
        case 11: rval = "RAKP-HMAC-MD5,MD5-128,none"; rnval = 12; break;
 
2570
        case 12: rval = "RAKP-HMAC-MD5,MD5-128,AES-CBC-128"; rnval = 13; break;
 
2571
        case 13: rval = "RAKP-HMAC-MD5,MD5-128,xRC4-128"; rnval = 14; break;
 
2572
        case 14: rval = "RAKP-HMAC-MD5,MD5-128,xRC4-40"; rnval = -1; break;
 
2573
        default:
 
2574
            if (*nval)
 
2575
                *nval = -1;
 
2576
            return EINVAL;
 
2577
        }
 
2578
    } else if (parm == 44) { /* max_priv_for_cipher_suite */
 
2579
        if (val < 0) {
 
2580
            if (nval)
 
2581
                *nval = 0;
 
2582
            return EINVAL;
 
2583
        }
 
2584
        switch (val) {
 
2585
        case 0: rval = "disabled"; rnval = 1; break;
 
2586
        case 1: rval = "callback"; rnval = 2; break;
 
2587
        case 2: rval = "user"; rnval = 3; break;
 
2588
        case 3: rval = "admin"; rnval = 4; break;
 
2589
        case 4: rval = "oem"; rnval = -1; break;
 
2590
        default:
 
2591
            if (*nval)
 
2592
                *nval = -1;
 
2593
            return EINVAL;
 
2594
        }
 
2595
    } else {
 
2596
        return ENOSYS;
 
2597
    }
 
2598
 
 
2599
    if (sval)
 
2600
        *sval = rval;
 
2601
    if (nval)
 
2602
        *nval = rnval;
 
2603
    return 0;
 
2604
}
 
2605
 
 
2606
int
 
2607
ipmi_lanconfig_enum_idx(unsigned int parm, int idx, const char **sval)
 
2608
{
 
2609
    char *rval;
 
2610
 
 
2611
    if ((parm < 10) || (parm > 14))
 
2612
        return ENOSYS;
 
2613
 
 
2614
    switch (idx) {
 
2615
    case 0: rval = "callback"; break;
 
2616
    case 1: rval = "user"; break;
 
2617
    case 2: rval = "operator"; break;
 
2618
    case 3: rval = "admin"; break;
 
2619
    case 4: rval = "oem"; break;
 
2620
    default: return EINVAL;
 
2621
    }
 
2622
 
 
2623
    if (sval)
 
2624
        *sval = rval;
 
2625
 
 
2626
    return 0;
 
2627
}
 
2628
 
 
2629
int
2480
2630
ipmi_lanconfig_get_val(ipmi_lan_config_t *lanc,
2481
2631
                       unsigned int      parm,
2482
2632
                       const char        **name,
2577
2727
 
2578
2728
    if (gdata[parm].iv_cnt) {
2579
2729
        count = gdata[parm].iv_cnt(lanc);
2580
 
        if (index >= count)
 
2730
        if (index >= (int) count)
2581
2731
            return E2BIG;
2582
2732
    }
2583
2733
 
2584
2734
    switch (gdata[parm].datatype) {
2585
2735
    case IPMI_LANCONFIG_INT:
2586
2736
    case IPMI_LANCONFIG_BOOL:
2587
 
        if (!ival)
2588
 
            break;
2589
2737
        if (gdata[parm].u.ival.sval)
2590
2738
            rv = gdata[parm].u.ival.sval(lanc, ival);
2591
2739
        else if (gdata[parm].u.ival.sval_v)
2621
2769
unsigned int
2622
2770
ipmi_lanconfig_str_to_parm(char *name)
2623
2771
{
2624
 
    int i;
 
2772
    unsigned int i;
2625
2773
    for (i=0; i<NUM_GDATA_ENTRIES; i++) {
2626
2774
        if (strcmp(name, gdata[i].fname) == 0)
2627
2775
            return i;