Exemple #1
0
char *ipifcaddpref6(struct Ipifc *ifc, char **argv, int argc)
{
	uint8_t onlink = 1;
	uint8_t autoflag = 1;
	uint64_t validlt = UINT64_MAX;
	uint64_t preflt = UINT64_MAX;
	uint64_t origint = NOW / 10 ^ 3;
	uint8_t prefix[IPaddrlen];
	int plen = 64;
	struct Iplifc *lifc;
	char addr[40], preflen[6];
	char *params[3];

	switch (argc) {
		case 7:
			preflt = atoi(argv[6]);
			/* fall through */
		case 6:
			validlt = atoi(argv[5]);
			/* fall through */
		case 5:
			autoflag = atoi(argv[4]);
			/* fall through */
		case 4:
			onlink = atoi(argv[3]);
			/* fall through */
		case 3:
			plen = atoi(argv[2]);
		case 2:
			break;
		default:
			return Ebadarg;
	}

	if ((parseip(prefix, argv[1]) != 6) ||
		(validlt < preflt) || (plen < 0) || (plen > 64) || (islinklocal(prefix))
		)
		return Ebadarg;

	lifc = kzmalloc(sizeof(struct Iplifc), 0);
	lifc->onlink = (onlink != 0);
	lifc->autoflag = (autoflag != 0);
	lifc->validlt = validlt;
	lifc->preflt = preflt;
	lifc->origint = origint;

	if (ifc->m->pref2addr != NULL)
		ifc->m->pref2addr(prefix, ifc->mac);
	else
		return Ebadarg;

	snprintf(addr, sizeof(addr), "%I", prefix);
	snprintf(preflen, sizeof(preflen), "/%d", plen);
	params[0] = "add";
	params[1] = addr;
	params[2] = preflen;

	return ipifcadd(ifc, params, 3, 0, lifc);
}
Exemple #2
0
int
v6addrtype(uint8_t *addr)
{
	if(isv4(addr) || ipcmp(addr, IPnoaddr) == 0)
		return unknownv6;
	else if(islinklocal(addr) ||
	    isv6mcast(addr) && (addr[1] & 0xF) <= Link_local_scop)
		return linklocalv6;
	else
		return globalv6;
}
Exemple #3
0
int v6addrtype(uint8_t * addr)
{
	if (isv6global(addr))
		return globalv6;
	if (islinklocal(addr))
		return linklocalv6;
	if (isv6mcast(addr))
		return multicastv6;
	if (issitelocal(addr))
		return sitelocalv6;
	return unknownv6;
}
Exemple #4
0
char*
ipifcadd6(Ipifc *ifc, char**argv, int argc)
{
	int plen = 64;
	int32_t origint = NOW / 1000, preflt = ~0L, validlt = ~0L;
	char addr[Maxv6repr], preflen[6];
	char *params[3];
	uint8_t autoflag = 1, onlink = 1;
	uint8_t prefix[IPaddrlen];
	Iplifc *lifc;

	switch(argc) {
	case 7:
		preflt = atoi(argv[6]);
		/* fall through */
	case 6:
		validlt = atoi(argv[5]);
		/* fall through */
	case 5:
		autoflag = atoi(argv[4]);
		/* fall through */
	case 4:
		onlink = atoi(argv[3]);
		/* fall through */
	case 3:
		plen = atoi(argv[2]);
		/* fall through */
	case 2:
		break;
	default:
		return Ebadarg;
	}

	if (parseip(prefix, argv[1]) != 6)
		return "bad ipv6 address";
	if (validlt < preflt)
		return "valid ipv6 lifetime less than preferred lifetime";
	if (plen < 0)
		return "negative ipv6 prefix length";
	/* i think that this length limit is bogus - geoff */
//	if (plen > 64)
//		return "ipv6 prefix length greater than 64;
	if (islinklocal(prefix))
		return "ipv6 prefix is link-local";

	lifc = smalloc(sizeof(Iplifc));
	lifc->onlink = (onlink != 0);
	lifc->autoflag = (autoflag != 0);
	lifc->validlt = validlt;
	lifc->preflt = preflt;
	lifc->origint = origint;

	/* issue "add" ctl msg for v6 link-local addr and prefix len */
	if(!ifc->medium->pref2addr)
		return "no pref2addr on interface";
	ifc->medium->pref2addr(prefix, ifc->mac);	/* mac → v6 link-local addr */
	snprint(addr, sizeof addr, "%I", prefix);
	snprint(preflen, sizeof preflen, "/%d", plen);
	params[0] = "add";
	params[1] = addr;
	params[2] = preflen;

	return ipifcadd(ifc, params, 3, 0, lifc);
}