Revision acc93efd sysdep/unix/main.c

View differences:

sysdep/unix/main.c
62 62
 *	Reading the Configuration
63 63
 */
64 64

  
65
#ifdef PATH_IPROUTE_DIR
66

  
67
static inline void
68
add_num_const(char *name, int val)
69
{
70
  struct symbol *s = cf_find_symbol(name);
71
  s->class = SYM_NUMBER;
72
  s->def = NULL;
73
  s->aux = val;
74
}
75

  
76
/* the code of read_iproute_table() is based on
77
   rtnl_tab_initialize() from iproute2 package */
78
static void
79
read_iproute_table(char *file, char *prefix, int max)
80
{
81
  char buf[512], namebuf[512];
82
  char *name;
83
  int val;
84
  FILE *fp;
85

  
86
  strcpy(namebuf, prefix);
87
  name = namebuf + strlen(prefix);
88

  
89
  fp = fopen(file, "r");
90
  if (!fp)
91
    return;
92

  
93
  while (fgets(buf, sizeof(buf), fp))
94
  {
95
    char *p = buf;
96

  
97
    while (*p == ' ' || *p == '\t')
98
      p++;
99

  
100
    if (*p == '#' || *p == '\n' || *p == 0)
101
      continue;
102
   
103
    if (sscanf(p, "0x%x %s\n", &val, name) != 2 &&
104
	sscanf(p, "0x%x %s #", &val, name) != 2 &&
105
	sscanf(p, "%d %s\n", &val, name) != 2 &&
106
	sscanf(p, "%d %s #", &val, name) != 2)
107
      continue;
108

  
109
    if (val < 0 || val > max)
110
      continue;
111

  
112
    for(p = name; *p; p++)
113
      if ((*p < 'a' || *p > 'z') && (*p < '0' || *p > '9') && (*p != '_'))
114
	*p = '_';
115

  
116
    add_num_const(namebuf, val);
117
  }
118

  
119
  fclose(fp);
120
}
121

  
122
#endif // PATH_IPROUTE_DIR
123

  
124

  
65 125
static int conf_fd;
66 126
static char *config_name = PATH_CONFIG;
67 127

  
......
78 138
sysdep_preconfig(struct config *c)
79 139
{
80 140
  init_list(&c->logfiles);
141

  
142
#ifdef PATH_IPROUTE_DIR
143
  // read_iproute_table(PATH_IPROUTE_DIR "/rt_protos", "ipp_", 256);
144
  read_iproute_table(PATH_IPROUTE_DIR "/rt_realms", "ipr_", 256);
145
  read_iproute_table(PATH_IPROUTE_DIR "/rt_scopes", "ips_", 256);
146
  read_iproute_table(PATH_IPROUTE_DIR "/rt_tables", "ipt_", 256);
147
#endif
81 148
}
82 149

  
83 150
int

Also available in: Unified diff