ucmd_netconsole.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* netconsole: ring-3 command. The debug-output mirror's configuration. */
  2. #include "ucmd_lib.h"
  3. #define NETLOG_PORT 19290
  4. static int arg_is(const char *arg, const char *word)
  5. {
  6. unsigned int i = 0;
  7. while (arg[i] && word[i] && arg[i] == word[i])
  8. i++;
  9. return arg[i] == '\0' && word[i] == '\0';
  10. }
  11. static void usage(void)
  12. {
  13. u_puts("netconsole: usage netconsole on|off|host <a.b.c.d>\n");
  14. }
  15. void _start(const char *arg)
  16. {
  17. struct sys_netinfo n;
  18. unsigned char ip[4];
  19. if (!arg || !arg[0]) {
  20. u_syscall1(SYS_NET_INFO, (int)&n);
  21. u_puts("netconsole: mirror ");
  22. u_puts(n.mirror_on ? "on" : "off");
  23. u_puts(", host ");
  24. u_put_ip(n.mirror_host);
  25. u_puts(", udp port ");
  26. u_putdec(NETLOG_PORT);
  27. u_putc('\n');
  28. usage();
  29. u_exit(1);
  30. }
  31. if (arg_is(arg, "on")) {
  32. u_syscall2(SYS_NETLOG_CONF, 1, 0);
  33. u_puts("netconsole: mirror on\n");
  34. u_exit(0);
  35. }
  36. if (arg_is(arg, "off")) {
  37. u_syscall2(SYS_NETLOG_CONF, 0, 0);
  38. u_puts("netconsole: mirror off\n");
  39. u_exit(0);
  40. }
  41. if (arg[0] == 'h' && arg[1] == 'o' && arg[2] == 's' && arg[3] == 't') {
  42. const char *p = arg + 4;
  43. while (*p == ' ')
  44. p++;
  45. if (*p == '\0' || u_parse_ip(p, ip) != 0) {
  46. usage();
  47. u_exit(1);
  48. }
  49. u_syscall2(SYS_NETLOG_CONF, -1, (int)ip);
  50. u_puts("netconsole: host ");
  51. u_put_ip(ip);
  52. u_putc('\n');
  53. u_exit(0);
  54. }
  55. usage();
  56. u_exit(1);
  57. }