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

📄 server6_parse.y

📁 DHCPv6协议在Linux操作系统下的一个客户端实现。
💻 Y
📖 第 1 页 / 共 2 页
字号:
				}				if (prefix1->plen == temp_seg->prefix.plen) {	     				if (!(ipv6addrcmp(&seg->min, &temp_seg->max) > 0					    || ipv6addrcmp(&seg->max, &temp_seg->min) < 0)) {		   				dprintf(LOG_ERR, "overlap range addr defined");		   				ABORT;					}				}				if (temp_seg->prev == NULL) { 					link->seglist = seg;					seg->prev = NULL;				} else {					temp_seg->prev->next = seg;					seg->prev = temp_seg->prev;				}				temp_seg->prev = seg;				seg->next = temp_seg;				break;			}		}		free(prefix1);		free(prefix2);	}	;groupdef		: grouphead '{' groupbody  '}' ';'	{		/* return to prev group scope if any */		currentgroup = pop_double_list(currentgroup);		/* leave current group scope */		currentscope = pop_double_list(currentscope);	}	;groupbody		: 	| groupbody groupparas	;groupparas		: hostdef	| pooldef	| linkdef	| rangedef	| prefixdef	| ifdef	| confdecl	;grouphead		: GROUP	{		struct scope *groupscope;		groupscope = (struct scope *)malloc(sizeof(*groupscope));		if (groupscope == NULL) {			dprintf(LOG_ERR, "group memory allocation failed");			ABORT;		}		memset(groupscope, 0, sizeof(*groupscope));		TAILQ_INIT(&groupscope->dnslist.addrlist);		/* set up current group */		currentgroup = push_double_list(currentgroup, groupscope);		if (currentgroup == NULL)			ABORT;		/* enter group scope  */		currentscope = push_double_list(currentscope, groupscope);		if (currentscope == NULL)			ABORT;	}	;hostdef		: hosthead '{' hostbody '}' ';'	{		struct host_decl *temp_host = hostlist;		while (temp_host)		{			if (temp_host->iaidinfo.iaid == host->iaidinfo.iaid) {				dprintf(LOG_ERR, "duplicated host %d redefined", 					host->iaidinfo.iaid);				ABORT;			}			temp_host = temp_host->next;		}		if (currentgroup) 			host->group = currentgroup->scope;		host->next = hostlist;		hostlist = host;		host = NULL;		/* leave host scope we know the current scope is not point to NULL*/		currentscope = pop_double_list(currentscope);	}	;hosthead		: HOST name	{		struct host_decl *temp_host = hostlist;		while (temp_host)		{			if (!strcmp(temp_host->name, $2)) {				dprintf(LOG_ERR, "duplicated host %s redefined", $2);				ABORT;			}			temp_host = temp_host->next;		}		host = (struct host_decl *)malloc(sizeof(*host));		if (host == NULL) {			dprintf(LOG_ERR, "fail to allocate memory");			ABORT;		}		memset(host, 0, sizeof(*host));		TAILQ_INIT(&host->addrlist);		TAILQ_INIT(&host->prefixlist);		TAILQ_INIT(&host->hostscope.dnslist.addrlist);		host->network = ifnetwork;		strncpy(host->name, $2, strlen($2));		/* enter host scope */		currentscope = push_double_list(currentscope, &host->hostscope);		if (currentscope == NULL)			ABORT;	}	;hostbody	: hostbody hostdecl	| hostdecl	;hostdecl	: DUID DUID_ID ';'	{		if (host == NULL) {			dprintf(LOG_DEBUG, "duid should be defined under host decl");			ABORT;		}		configure_duid($2, &host->cid);	}	| iaiddef	| hostparas	;iaiddef	: IAIDINFO '{' iaidbody '}' ';'	{	}	;iaidbody	: iaidbody RENEWTIME number_or_infinity ';'	{		host->iaidinfo.renewtime = $3;	}	| iaidbody REBINDTIME number_or_infinity ';'	{		host->iaidinfo.rebindtime = $3;	}	| iaidpara	;iaidpara	: IAID NUMBER ';'	{		if (host == NULL) {			dprintf(LOG_DEBUG, "iaid should be defined under host decl");			ABORT;		}		host->iaidinfo.iaid = $2;	}	;	hostparas	: hostparas hostpara	| hostpara	;hostpara	: hostaddr6	{		if (host == NULL) {			dprintf(LOG_DEBUG, "address should be defined under host decl");			ABORT;		}		dhcp6_add_listval(&host->addrlist, $1, DHCP6_LISTVAL_DHCP6ADDR);		if (hash_add(host_addr_hash_table, &($1->addr), $1) != 0) {			dprintf(LOG_ERR, "%s" "hash add lease failed for %s",				FNAME, in6addr2str(&($1->addr), 0));			free($1);			return (-1);		}	}	| hostprefix6	{		if (host == NULL) {			dprintf(LOG_DEBUG, "prefix should be defined under host decl");			ABORT;		}		dhcp6_add_listval(&host->prefixlist, $1, DHCP6_LISTVAL_DHCP6ADDR);	}	| optiondecl	;hostaddr6	: ADDRESS '{' addr6para '}' ';'	{		$3->type = IANA;		$$ = $3;	}	;hostprefix6	: PREFIX '{' addr6para '}' ';'	{		$3->type = IAPD;		$$ = $3;	}	;	addr6para	: addr6para VALIDLIFETIME number_or_infinity ';'	{		$1->validlifetime = $3;	}	| addr6para PREFERLIFETIME number_or_infinity ';'	{		$1->preferlifetime = $3;	}	| v6address	{		$$ = $1;	}	;v6address	: IPV6ADDR '/' NUMBER ';'	{		struct dhcp6_addr *temp;		temp = (struct dhcp6_addr *)malloc(sizeof(*temp));		if (temp == NULL) {			dprintf(LOG_ERR, "v6addr memory allocation failed");			ABORT;		}		memset(temp, 0, sizeof(*temp));		memcpy(&temp->addr, &$1, sizeof(temp->addr));		if ($3 > 128 || $3 < 0) {			dprintf(LOG_ERR, "invalid prefix length in line %d", num_lines);			ABORT;		}		temp->plen = $3;		$$ = temp;	}	;optiondecl	: optionhead optionpara	;optionhead	: SEND	{				if (!currentscope) { 			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}	}		| ALLOW	{				if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		allow = 1;	}	| OPTION	{				if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}	}	;optionpara	: RAPIDCOMMIT ';'	{		if (allow) 			currentscope->scope->allow_flags |= DHCIFF_RAPID_COMMIT;		else 			currentscope->scope->send_flags |= DHCIFF_RAPID_COMMIT;	}	| TEMPIPV6ADDR ';'	{		if (allow) 			currentscope->scope->allow_flags |= DHCIFF_TEMP_ADDRS;		else 			currentscope->scope->send_flags |= DHCIFF_TEMP_ADDRS;	}	| UNICAST ';'	{		if (allow) 			currentscope->scope->allow_flags |= DHCIFF_UNICAST;		else 			currentscope->scope->send_flags |= DHCIFF_UNICAST;	}	| INFO_ONLY ';'	{		if (allow) 			currentscope->scope->allow_flags |= DHCIFF_INFO_ONLY;		else			currentscope->scope->send_flags |= DHCIFF_INFO_ONLY;	}	| DNS_SERVERS dns_paras ';'	{	}	;dns_paras	: dns_paras dns_para	| dns_para	;dns_para	: IPV6ADDR 	{		dhcp6_add_listval(&currentscope->scope->dnslist.addrlist, &$1,			DHCP6_LISTVAL_ADDR6);	}	| STRING	{		struct domain_list *domainname, *temp;		int len = 0;		domainname = (struct domain_list *)malloc(sizeof(*domainname));		if (domainname == NULL)			ABORT;		len = strlen($1);		if (len > MAXDNAME) 			ABORT;		strncpy(domainname->name, $1, len);		domainname->name[len] = '\0';		domainname->next = NULL;		if (currentscope->scope->dnslist.domainlist == NULL) {			currentscope->scope->dnslist.domainlist = domainname;			dprintf(LOG_DEBUG, "add domain name %s", domainname->name);		} else {			for (temp = currentscope->scope->dnslist.domainlist; temp;			     temp = temp->next) {				if (temp->next == NULL) {					dprintf(LOG_DEBUG, "add domain name %s", 						domainname->name);					temp->next = domainname;					break;				}			}		}	}	;confdecl		: paradecl	| optiondecl	;paradecl	: RENEWTIME number_or_infinity ';'	{		if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		currentscope->scope->renew_time = $2;	}	| REBINDTIME number_or_infinity ';'	{			if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		currentscope->scope->rebind_time = $2;	}	| VALIDLIFETIME number_or_infinity ';'	{		if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		currentscope->scope->valid_life_time = $2;		if (currentscope->scope->prefer_life_time != 0 && 		    currentscope->scope->valid_life_time <		    currentscope->scope->prefer_life_time) {			dprintf(LOG_ERR, "%s" 				"validlifetime is less than preferlifetime", FNAME);			ABORT;		}	}	| PREFERLIFETIME number_or_infinity ';'	{		if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		currentscope->scope->prefer_life_time = $2;		if (currentscope->scope->valid_life_time != 0 &&		    currentscope->scope->valid_life_time <		    currentscope->scope->prefer_life_time) {			dprintf(LOG_ERR, "%s" 				"validlifetime is less than preferlifetime", FNAME);			ABORT;		}	}	| PREFERENCE NUMBER ';'	{		if (!currentscope) {			currentscope = push_double_list(currentscope, &globalgroup->scope);			if (currentscope == NULL)				ABORT;		}		if ($2 < 0 || $2 > 255)			dprintf(LOG_ERR, "%s" "bad server preference number", FNAME);		currentscope->scope->server_pref = $2;	}	;number_or_infinity	: NUMBER	{		$$ = $1; 	}	| INFINITY	{		$$ = DHCP6_DURATITION_INFINITE;	}	;name	: STRING	{		$$ = $1;	}	;%%staticvoid cleanup(void){	/* it is not necessary to free all the pre malloc(), if it fails, 	 * exit will free them automatically.	 */}voidsfyyerror(char *msg){	cleanup();	dprintf(LOG_ERR, "%s in line %d: %s ", msg, num_lines, sfyytext);}

⌨️ 快捷键说明

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