summaryrefslogtreecommitdiffstats
path: root/loader/ibft.c
blob: b3a382759d1a336110ad3df7627b665cbd11ca13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
   File name: ibft.c
   Date:      2008/09/02
   Author:    Martin Sivak <msivak@redhat.com>

   Copyright (C) 2008 Red Hat

   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
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.
*/


#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <libiscsi.h>
#include "ibft.h"

struct libiscsi_network_config ibft_context;
int ibft_ispresent = 0;
int ibft_initialized = 0;

int ibft_init(void)
{
  int ret;

  memset(&ibft_context, 0, sizeof(ibft_context));

  ret = libiscsi_get_firmware_network_config(&ibft_context);

  /* ret == 0 -> OK */
  ibft_ispresent = !ret;
  ibft_initialized = 1;

  return ibft_initialized;
}

/* Is iBFT available on this system */
int ibft_present()
{
  if(!ibft_initialized)
    ibft_init();

  return ibft_ispresent;
}

/* Is the iBFT network configured to use DHCP */
int ibft_iface_dhcp()
{
  if(!ibft_initialized)
    ibft_init();

  if(!ibft_present())
    return -1;

  return ibft_context.dhcp;
}

#define ibft_iface_charfunc(name, var) char* ibft_iface_##name()\
{\
  if(!ibft_initialized)\
    ibft_init();\
\
  if(!ibft_present())\
    return NULL;\
\
  if(!strlen(ibft_context.var))\
    return NULL;\
\
  return ibft_context.var;\
}


/* Get the iBFT MAC address */
ibft_iface_charfunc(mac, mac_address)

/* Get the iBFT ip address */
ibft_iface_charfunc(ip, ip_address)

/* Get the iBFT subnet mask */
ibft_iface_charfunc(mask, netmask)

/* Get the iBFT gateway */
ibft_iface_charfunc(gw, gateway)

/* Get the iBFT iface name */
ibft_iface_charfunc(iface, iface_name)

/* Get the iBFT dns servers */
ibft_iface_charfunc(dns1, primary_dns)
ibft_iface_charfunc(dns2, secondary_dns)