int set_lladdr(const char *ifname, const char *lladdr, const struct env_set *es) { char cmd[256]; int r; if (!ifname || !lladdr) return -1; #if defined(TARGET_LINUX) #ifdef CONFIG_FEATURE_IPROUTE openvpn_snprintf (cmd, sizeof (cmd), IPROUTE_PATH " link set addr %s dev %s", lladdr, ifname); #else openvpn_snprintf (cmd, sizeof (cmd), IFCONFIG_PATH " %s hw ether %s", ifname, lladdr); #endif #elif defined(TARGET_SOLARIS) openvpn_snprintf (cmd, sizeof (cmd), IFCONFIG_PATH " %s ether %s", ifname, lladdr); #elif defined(TARGET_OPENBSD) openvpn_snprintf (cmd, sizeof (cmd), IFCONFIG_PATH " %s lladdr %s", ifname, lladdr); #elif defined(TARGET_DARWIN) openvpn_snprintf (cmd, sizeof (cmd), IFCONFIG_PATH " %s lladdr %s", ifname, lladdr); #elif defined(TARGET_FREEBSD) openvpn_snprintf (cmd, sizeof (cmd), IFCONFIG_PATH " %s ether %s", ifname, lladdr); #else msg (M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system."); return -1; #endif r = system_check (cmd, es, M_WARN, "ERROR: Unable to set link layer address."); if (r) msg (M_INFO, "TUN/TAP link layer address set to %s", lladdr); return r; }
/*ARGSUSED*/ int main(void *cookie, char **argv, int argc) { /* * bpath is the boot device path buffer. * bargs is the boot arguments buffer. */ static char bpath[OBP_MAXPATHLEN], bargs[OBP_MAXPATHLEN]; boolean_t user_specified_filename; prom_init("boot", cookie); fiximp(); system_check(); dprintf("\nboot: V%d /boot interface.\n", BO_VERSION); #ifdef HALTBOOT prom_enter_mon(); #endif /* HALTBOOT */ init_memlists(); #ifdef DEBUG_LISTS dprintf("Physmem avail:\n"); if (debug) print_memlist(pfreelistp); dprintf("Virtmem avail:\n"); if (debug) print_memlist(vfreelistp); dprintf("Phys installed:\n"); if (debug) print_memlist(pinstalledp); prom_enter_mon(); #endif /* DEBUG_LISTS */ /* * Initialize the default filename (exported as "default-name" and * used by kadb). */ set_default_filename(defname); /* * Parse the arguments ASAP in case there are any flags which may * affect execution. */ /* * filename is the path to the standalone. Initialize it to the empty * string so we can tell whether the user specified it in the * arguments. */ filename[0] = '\0'; /* * Fetch the boot arguments from the PROM and split the filename off * if it's there. */ init_bootargs(filename, sizeof (filename), bargs, sizeof (bargs)); /* * kadb was delivered as a standalone, and as such, people got used to * typing `boot kadb'. kmdb isn't a standalone - it is loaded by krtld * as just another kernel module. For compatibility, though, when we * see an attempt to `boot kadb' or `boot kmdb', we'll transform that * into a `boot -k' (or equivalent). */ if (strcmp(filename, "kmdb") == 0 || strcmp(filename, "kadb") == 0) { boothowto |= RB_KMDB; *filename = '\0'; /* let boot figure out which unix to use */ } bootflags(bargs, sizeof (bargs)); user_specified_filename = (filename[0] != '\0'); /* Fetch the boot path from the PROM. */ (void) strncpy(bpath, prom_bootpath(), sizeof (bpath) - 1); bpath[sizeof (bpath) - 1] = '\0'; dprintf("arch: %s\n", is_sun4v ? "sun4v" : "sun4u"); dprintf("bootpath: 0x%p %s\n", (void *)bpath, bpath); dprintf("bootargs: 0x%p %s\n", (void *)bargs, bargs); dprintf("filename: 0x%p %s\n", (void *)filename, filename); dprintf("kernname: 0x%p %s\n", (void *)kernname, kernname); /* * *v2path will be exported to the standalone as the boot-path boot * property. */ v2path = bpath; /* * Our memory lists should be "up" by this time */ setup_bootops(); /* * If bpath is a network card, set v2path to a copy of bpath with the * options stripped off. */ mangle_os_bootpath(bpath); /* * Not necessary on sun4v as nvram is virtual * and kept by the guest manager on the SP. */ if (!is_sun4v) { retain_nvram_page(); } if (bootprog(bpath, bargs, user_specified_filename) == 0) { post_mountroot(filename, NULL); /*NOTREACHED*/ } return (0); }
int main(int argc, char **argv) { struct fwr rule; int fd, ret, f = 0; exec = argv[0]; if (argc < 2) { print_usage(); return -1; } if (!strcmp(argv[1], "mknod") && argc == 2) { if (mknod(IPFIREWALL_DEV, S_IFCHR, makedev(IPFIREWALL_MAJOR, 0)) < 0) { perror("mknod " IPFIREWALL_DEV); return -1; } return 0; } if (!strcmp(argv[1], "unlink") && argc == 2) { if (unlink(IPFIREWALL_DEV) < 0) { perror("unlink " IPFIREWALL_DEV); return -1; } return 0; } if (!strcmp(argv[1], "insmod") && argc == 2) { if (system_check("insmod " IPFIREWALL_MOD IPFIREWALL_MOD_EXT) < 0) return -1; return 0; } if (!strcmp(argv[1], "rmmod") && argc == 2) { if (system_check("rmmod " IPFIREWALL_MOD) < 0) return -1; return 0; } fd = open(IPFIREWALL_DEV, O_RDWR); if (fd < 0) { perror("open " IPFIREWALL_DEV); return -1; } if (!strcmp(argv[1], "test") && argc == 2) { close(fd); return 0; } if (!strcmp(argv[1], "invalid") && argc == 2) { if (ioctl(fd, 42, NULL) < 0) { if (errno != ENOTTY) { perror("ioctl 42"); close(fd); return -1; } close(fd); return 0; } perror("ioctl 42"); close(fd); return -1; } if (!strcmp(argv[1], "enable") && argc == 2) { if (ioctl(fd, FW_ENABLE, NULL) < 0) { perror("ioctl FW_ENABLE"); close(fd); return -1; } close(fd); return 0; } if (!strcmp(argv[1], "disable") && argc == 2) { if (ioctl(fd, FW_DISABLE, NULL) < 0) { perror("ioctl FW_DISABLE"); close(fd); return -1; } close(fd); return 0; } if ((!strcmp(argv[1], "add") || !strcmp(argv[1], "find")) && argc == 6) { parse_ip(argv[2], &rule.ip_src, &rule.ip_src_mask); parse_ip(argv[3], &rule.ip_dst, &rule.ip_dst_mask); parse_range(argv[4], &rule.port_src[0], &rule.port_src[1]); parse_range(argv[5], &rule.port_dst[0], &rule.port_dst[1]); if (argv[1][0] == 'a') { /* add rule */ if (ioctl(fd, FW_ADD_RULE, &rule) < 0) { perror("ioctl FW_ADD_RULE"); close(fd); return -1; } close(fd); return 0; } f = 1; } if (f || (!strcmp(argv[1], "list") && argc == 2)) { struct fwr *fwr = NULL; int size, i; do { size = 0; if (ioctl(fd, FW_LIST, &size) < 0 && errno != ENOSPC) { perror("ioctl FW_LIST"); close(fd); return -1; } fwr = (struct fwr *) realloc(fwr, size * sizeof(struct fwr)); if (!fwr) { fprintf(stderr, "out of memory\n"); close(fd); return -1; } *(int*) fwr = size; size = ioctl(fd, FW_LIST, fwr); if (size < 0 && errno != ENOSPC) { perror("ioctl FW_LIST"); close(fd); return -1; } } while (size < 0); close(fd); if (f) { /* find rule */ ret = -1; for (i = 0; i < size && ret; i++) if (!memcmp(&fwr[i], &rule, sizeof(struct fwr))) ret = 0; if (ret) fprintf(stderr, "rule not found\n"); } else { /* list rules */ ret = size; for (i = 0; i < size; i++) printf(NIPQUAD_FMT "/%d " NIPQUAD_FMT "/%d %d:%d %d:%d\n", NIPQUAD(fwr[i].ip_src), mask_len(fwr[i].ip_src_mask), NIPQUAD(fwr[i].ip_dst), mask_len(fwr[i].ip_dst_mask), ntohs(fwr[i].port_src[0]), ntohs(fwr[i].port_src[1]), ntohs(fwr[i].port_dst[0]), ntohs(fwr[i].port_dst[1])); } if (fwr) free(fwr); return ret; } print_usage(); close(fd); return -1; }