Skip to content

Commit

Permalink
ibft: re-added ibft parsing utilities in C
Browse files Browse the repository at this point in the history
Added also root-dir handling to pass tests with our
faked ibft sysfs tree in testing on non ibft system.
  • Loading branch information
mtomaschewski committed Feb 20, 2014
1 parent 8363d71 commit 579cf89
Show file tree
Hide file tree
Showing 14 changed files with 518 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ libwicked_la_SOURCES = \
firmware.c \
fsm.c \
fsm-policy.c \
ibft.c \
ifconfig.c \
ifevent.c \
iflist.c \
Expand Down Expand Up @@ -163,6 +164,7 @@ wicked_headers = \
dhcp6/lease.h \
dhcp6/options.h \
duid.h \
ibft.h \
ipv6_priv.h \
kernel.h \
leasefile.h \
Expand Down
129 changes: 129 additions & 0 deletions src/ibft.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Routines for iBFT (iSCSI Boot Firmware Table) NIC
*
* Copyright (C) 2010-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/> or write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Authors:
* Marius Tomaschewski <mt@suse.de>
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>

#include <wicked/types.h>
#include <wicked/netinfo.h>
#include <wicked/logging.h>

#include "ibft.h"
#include "util_priv.h"

/* iBFT related constants */
#define NI_SYSFS_FIRMWARE_IBFT_PATH "/sys/firmware/ibft"
#define NI_SYSFS_IBFT_INI_PREFIX "initiator"
#define NI_SYSFS_IBFT_NIC_PREFIX "ethernet"
#define NI_SYSFS_IBFT_TGT_PREFIX "target"

/* ibft nic array chunk size */
#define NI_IBFT_NIC_ARRAY_CHUNK 2

ni_ibft_nic_t *
ni_ibft_nic_new()
{
ni_ibft_nic_t *nic;

nic = xcalloc(1, sizeof(*nic));
ni_assert(nic);

nic->users = 1;
return nic;
}

ni_ibft_nic_t *
ni_ibft_nic_ref(ni_ibft_nic_t *nic)
{
ni_assert(nic && nic->users);
nic->users++;
return nic;
}

void
ni_ibft_nic_free(ni_ibft_nic_t *nic)
{
if (nic) {
ni_assert(nic->users);
nic->users--;
if(nic->users == 0) {
ni_string_free(&nic->node);
ni_string_free(&nic->ifname);
ni_string_free(&nic->devpath);
ni_string_free(&nic->hostname);
free(nic);
}
}
}

/* ------------------------------------------------------------------------- */

void
ni_ibft_nic_array_init(ni_ibft_nic_array_t *nics)
{
memset(nics, 0, sizeof(*nics));
}

void
ni_ibft_nic_array_destroy(ni_ibft_nic_array_t *nics)
{
if (nics) {
while(nics->count--) {
ni_ibft_nic_free(nics->data[nics->count]);
nics->data[nics->count] = NULL;
}
free(nics->data);
memset(nics, 0, sizeof(*nics));
}
}

static void
__ni_ibft_nic_array_realloc(ni_ibft_nic_array_t *nics, unsigned int newsize)
{
ni_ibft_nic_t **newdata;
unsigned int i;

newsize = (newsize + NI_IBFT_NIC_ARRAY_CHUNK);
newdata = realloc(nics->data, newsize * sizeof(ni_ibft_nic_t *));
ni_assert(newdata != NULL);

nics->data = newdata;
for(i = nics->count; i < newsize; ++i) {
nics->data[i] = NULL;
}
}

void
ni_ibft_nic_array_append(ni_ibft_nic_array_t *nics, ni_ibft_nic_t *nic)
{
if (nics && nic) {
if((nics->count % NI_IBFT_NIC_ARRAY_CHUNK) == 0)
__ni_ibft_nic_array_realloc(nics, nics->count);

nics->data[nics->count++] = ni_ibft_nic_ref(nic);
}
}
73 changes: 73 additions & 0 deletions src/ibft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Routines for iBFT (iSCSI Boot Firmware Table) NIC
*
* Copyright (C) 2010-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/> or write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Authors:
* Marius Tomaschewski <mt@suse.de>
*
*/
#ifndef __WICKED_IBFT_H__
#define __WICKED_IBFT_H__

typedef struct ni_ibft_nic {
unsigned int users; /* refcount */

char * node; /* ethernet0, ... */

char * ifname; /* physical interface name */
unsigned int ifindex; /* physical interface index */

char * devpath; /* sysfs path to physical device */
unsigned int index;
unsigned int flags;
unsigned int origin;
unsigned int vlan;

ni_hwaddr_t hwaddr;
ni_sockaddr_t ipaddr;
unsigned int prefix_len;
ni_sockaddr_t dhcp;
ni_sockaddr_t gateway;
ni_sockaddr_t primary_dns;
ni_sockaddr_t secondary_dns;
char * hostname;
} ni_ibft_nic_t;


#define NI_IBFT_NIC_ARRAY_INIT { 0, NULL }

typedef struct ni_ibft_nic_array {
unsigned int count;
ni_ibft_nic_t **data; /* array of refcount pointers! */
} ni_ibft_nic_array_t;


extern ni_ibft_nic_t * ni_ibft_nic_new(void);
extern ni_ibft_nic_t * ni_ibft_nic_ref (ni_ibft_nic_t *nic);
extern void ni_ibft_nic_free(ni_ibft_nic_t *nic);

extern void ni_ibft_nic_array_init(ni_ibft_nic_array_t *nics);
extern void ni_ibft_nic_array_destroy(ni_ibft_nic_array_t *nics);
extern void ni_ibft_nic_array_append(ni_ibft_nic_array_t *nics,
ni_ibft_nic_t *nic);

extern int ni_sysfs_ibft_scan_nics(ni_ibft_nic_array_t *nics,
const char *root);

#endif /* __WICKED_IBFT_H__ */
Loading

0 comments on commit 579cf89

Please sign in to comment.