⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ha_config.c

📁 mobile ip 在linux下的一种实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: ha_config.c,v 1.27 2001/10/20 10:16:11 jm Exp $ * Home Agent - configuration reading routines * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2001, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#include <stdlib.h>#include <stdio.h>#include <assert.h>#include <string.h>#include <syslog.h>#include <unistd.h>#include "auth.h"#include "ha_config.h"#include "ha.h"#include "fileio.h"#include "util.h"#define ASSERT assertstruct load_ha_data {        struct ha_config *cfg;        int process_spi_list;        int process_authorized_list;	int process_fa_spi_list;	int process_interfaces;};static int process_load_ha(void *voidptr, char *key, char *data);static int process_load_ha_spi_list(struct load_ha_data *ha, char *key,                                    char *data);static int process_load_ha_authorized_list(struct load_ha_data *ha, char *key,					   char *data);static int process_load_fa_spi_list(struct load_ha_data *ha, char *key,                                    char *data);/* clean up home agent configuration settings */voidcleanup_config(struct ha_config *cfg){	struct spi_entry *spi;	struct fa_spi_entry *fa_spi;	struct authorized_entry *auth;	struct interface_entry *iface;	if (cfg == NULL) return;	spi = (struct spi_entry *) list_remove_first(&cfg->spi_list);	while (spi != NULL) {		free(spi);		spi = (struct spi_entry *) list_remove_first(&cfg->spi_list);	}	/* remove all from authorized list */	auth = (struct authorized_entry *)		list_remove_first(&cfg->authorized_list);	while (auth != NULL) {		free(auth);		auth = (struct authorized_entry *)			list_remove_first(&cfg->authorized_list);	}	fa_spi = (struct fa_spi_entry *) list_remove_first(&cfg->fa_spi_list);	while (fa_spi != NULL) {		free(fa_spi);		fa_spi = (struct fa_spi_entry *)			list_remove_first(&cfg->fa_spi_list);	}	iface = (struct interface_entry *)		list_remove_first(&cfg->interfaces);	while (iface != NULL) {		if (iface->icmp_sock >= 0)			close(iface->icmp_sock);		if (iface->udp_sock >= 0)			close(iface->udp_sock);		if (iface->udp_bc_sock >= 0)			close(iface->udp_bc_sock);		if (iface->udp_bc_sock2 >= 0)			close(iface->udp_bc_sock2);		free(iface);		iface = (struct interface_entry *)			list_remove_first(&cfg->interfaces);	}}intload_config(struct ha_config *cfg, char *program_name, char *config_file){	FILE *file;	struct load_ha_data ha;	ASSERT(cfg);	ha.cfg = cfg;	memset(cfg, 0, sizeof(struct ha_config));	ha.process_spi_list = FALSE;	list_init(&cfg->spi_list);	ha.process_authorized_list = FALSE;	list_init(&cfg->authorized_list);	ha.process_fa_spi_list = FALSE;	list_init(&cfg->fa_spi_list);	ha.process_interfaces = FALSE;	list_init(&cfg->interfaces);	/* set default values */	cfg->max_bindings = HA_DEFAULT_MAX_BINDINGS;	cfg->ha_default_tunnel_lifetime = HA_DEFAULT_TUNNEL_LIFETIME;	cfg->reg_error_reply_interval = HA_DEFAULT_REG_ERROR_REPLY_INTERVAL;	cfg->syslog_facility = HA_DEFAULT_SYSLOG_FACILITY;	cfg->udpport = HA_DEFAULT_REG_PORT;	cfg->socket_priority = -1;	cfg->enable_triangle_tunneling = TRUE;	cfg->enable_reverse_tunneling = TRUE;	cfg->pubkey_hash_method = HASH_METHOD_CHECK;	file = fopen(config_file, "r");        if (file == NULL) {		fprintf(stderr,			"%s: Could not open configuration file '%s'.\n",			program_name, config_file);		return FALSE;	}        if (load_data(&ha, file, process_load_ha) == FALSE) {                fprintf(stderr,                        "%s: Error while interpreting file '%s'!\n",                        program_name, config_file);                fclose(file);		cleanup_config(cfg);                return FALSE;        }        fclose(file);	openlog("home agent", LOG_PID | LOG_CONS, cfg->syslog_facility);        return TRUE;}static intprocess_interfaces(struct load_ha_data *ha, char *key, char *data){	struct ha_config *cfg;	struct interface_entry *iface;	char *pos;	if (strcmp(key, "INTERFACES_END") == 0) {		assert(ha->process_interfaces == TRUE);		ha->process_interfaces = FALSE;		return 0;	}	cfg = ha->cfg;	iface = malloc(sizeof(struct interface_entry));	if (iface == NULL) {		fprintf(stderr,			"process_interfaces: not enough memory for "			"struct interface_entry\n");		return -1;	}	memset(iface, 0, sizeof(iface));	list_init_node(&iface->node);	dynamics_strlcpy(iface->dev, key, IFNAMSIZ);	pos = data;	while (*pos == ' ' || *pos == '\t') pos++;	if (*pos == '\0' || sscanf(pos, "%d", &iface->ha_disc) != 1 ||	    (iface->ha_disc < 0 || iface->ha_disc > 1)) {		fprintf(stderr,			"process_interfaces: invalid ha_disc (interface=%s)\n",			iface->dev);		free(iface);		return -1;	}	while (*pos != ' ' && *pos != '\t' && *pos != '\0') pos++;	while (*pos == ' ' || *pos == '\t') pos++;	if (*pos == '\0' || sscanf(pos, "%d", &iface->agentadv) != 1) {		fprintf(stderr, "process_interfaces: invalid agentadv "			"(interface=%s)\n", iface->dev);		free(iface);		return -1;	}	while (*pos != ' ' && *pos != '\t' && *pos != '\0') pos++;	while (*pos == ' ' || *pos == '\t') pos++;	if (*pos == '\0' || sscanf(pos, "%d", &iface->interval) != 1) {		fprintf(stderr, "process_interfaces: invalid interval "			"(interface=%s)\n", iface->dev);		free(iface);		return -1;	}	if (iface->interval < 1) {		fprintf(stderr, "process_interfaces: advertisement interval "			"too short (must be at least one second)\n");		free(iface);		return -1;	}	while (*pos != ' ' && *pos != '\t' && *pos != '\0') pos++;	while (*pos == ' ' || *pos == '\t') pos++;	iface->force_addr.s_addr = 0;	if (*pos != '\0' && load_ip_address(pos, &iface->force_addr) != TRUE) {		fprintf(stderr,	"process_interfaces: invalid IP address "			"(interface=%s)\n", iface->dev);		free(iface);		return -1;	}	iface->icmp_sock = -1;	iface->udp_sock = -1;	iface->udp_bc_sock = -1;	iface->udp_bc_sock2 = -1;	list_add_tail(&cfg->interfaces, &iface->node);	return 0;}/* * process_load_ha * * Process loading of the ha_data * * Return values: *  -2: consistency error, *  -1: error, *   0: ok, *   1: end */static int process_load_ha(void *voidptr, char *key, char *data){	struct load_ha_data *ha;	struct ha_config *cfg;	ha = voidptr;	cfg = ha->cfg;	if (ha->process_spi_list == TRUE) {		return process_load_ha_spi_list(ha, key, data);	}	if (ha->process_authorized_list == TRUE) {		return process_load_ha_authorized_list(ha, key, data);	}	if (ha->process_fa_spi_list == TRUE) {		return process_load_fa_spi_list(ha, key, data);	}	if (ha->process_interfaces == TRUE) {		return process_interfaces(ha, key, data);	}	if (strcmp(key, "MaxBindings") == 0) {		if (load_int(data, &cfg->max_bindings) == TRUE) return 0;		return -1;	}	if (strcmp(key, "HADefaultTunnelLifetime") == 0) {		if (load_int(data, &cfg->ha_default_tunnel_lifetime) == TRUE) {			return 0;		}		return -1;	}	if (strcmp(key, "RegErrorReplyInterval") == 0) {		if (load_int(data, &cfg->reg_error_reply_interval) == TRUE) {			return 0;		}		return -1;	}	if (strcmp(key, "SECURITY_BEGIN") == 0) {		if (ha->process_authorized_list ||		    ha->process_spi_list ||		    ha->process_fa_spi_list || ha->process_interfaces) {			fprintf(stderr, "List processing error while handling "				"SECURITY_BEGIN\n");			return -1;		}		ha->process_spi_list = TRUE;		return 0;	}	if (strcmp(key, "AUTHORIZEDLIST_BEGIN") == 0) {		if (ha->process_authorized_list ||		    ha->process_spi_list ||		    ha->process_fa_spi_list || ha->process_interfaces) {			fprintf(stderr, "List processing error while handling "				"AUTHORIZEDLIST_BEGIN\n");			return -1;		}		ha->process_authorized_list = TRUE;		return 0;	}	if (strcmp(key, "FA_SECURITY_BEGIN") == 0) {		if (ha->process_authorized_list ||		    ha->process_spi_list ||		    ha->process_fa_spi_list || ha->process_interfaces) {			fprintf(stderr, "List processing error while handling "				"FA_SECURITY_BEGIN\n");			return -1;		}		ha->process_fa_spi_list = TRUE;		return 0;	}	if (strcmp(key, "INTERFACES_BEGIN") == 0) {		if (ha->process_authorized_list ||		    ha->process_spi_list ||		    ha->process_fa_spi_list || ha->process_interfaces) {			fprintf(stderr, "List processing error while handling "				"INTERFACES_BEGIN\n");			return -1;		}		ha->process_interfaces = TRUE;		return 0;	}	if (strcmp(key, "SyslogFacility") == 0) {                if (load_syslog_facility(data,                                         &cfg->syslog_facility) == TRUE) {                        return 0;                }                return -1;	}        if (strcmp(key, "HAAPIReadSocketPath") == 0) {                if (load_char_table(data, cfg->ha_api_read_socket_path,                                    MAXFILENAMELEN) == TRUE) {                        return 0;                }                return -1;        }        if (strcmp(key, "HAAPIReadSocketGroup") == 0) {                if (load_char_table(data, cfg->ha_api_read_socket_group,                                    MAXGROUPNAMELEN) == TRUE) {                        return 0;                }                return -1;        }        if (strcmp(key, "HAAPIReadSocketOwner") == 0) {                if (load_char_table(data, cfg->ha_api_read_socket_owner,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -