From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from tb-mx1.topicbox.com (localhost.local [127.0.0.1]) by tb-mx1.topicbox.com (Postfix) with ESMTP id 519B41ABE708 for ; Sun, 2 Jun 2024 05:05:52 -0400 (EDT) (envelope-from marcel@telka.sk) Received: from tb-mx1.topicbox.com (localhost [127.0.0.1]) by tb-mx1.topicbox.com (Authentication Milter) with ESMTP id 3919462F9AE; Sun, 2 Jun 2024 05:05:52 -0400 ARC-Seal: i=1; a=rsa-sha256; cv=none; d=topicbox.com; s=arcseal; t= 1717319152; b=tq5eYc0j8xnHvf3c0FJsxSyvB0qH9q1VjrCnsAVZ3xWDGOHHy9 boMXbZNp0TctW7+kxX+TnesfmG3NnWEQv9oII2RHO4OqR0aU0wM7DdwjUvPKEub1 NnV9fAjVj0AgS2mqkF6NBaEqhyGc0aIMLl8AegCM51tnOKg0SW8Qjo1ykb+L73/4 i/P5Ep/uUoIL9vK1o/WD/Ia4vrFaL4/x40dUSRAvbvZfPkPHZJgoBVt9GeWXYspR d7Yvve7Y8TXsxQrUpxBCCLBSx5/hgIWU583MfJhf8j+papdhrbrQYm2d3JN7LbVY jhXABQlIs8Q7S5Ag+HAKoysb0B/W2YYxzxxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= topicbox.com; h=date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; s=arcseal; t=1717319152; bh=7vaoMiCPTp/3X/WaaY7bt8X0wm5vikB/gAFG/Dz/Xmw=; b=Mg8WgAXc0rLN cLYu//qT9skrz870OkIbwrRp9mVDFUvQWmkfzp7p+1TA2vOHc67F8LIo9he8jP3u 0peq0PNoiGjMaImhXqzBzzzr2BORzsu/VrNE5SHncZJ7caLW25c1X1RrbJEthmgp FwvYlkqgkHQD7A/PTKaxxuWCv3P41rjyrKWFIym1aa/StcKirhc65inxMrF68dQN ThdwrQvbzc0JW8Mj6f1rPKXc00AfkivpiX8fkGVyHn/L1sv1Ff8LVhtSOB6pvOQ6 kfo4GIxZVCx2fgHrRZa0Rwiz3Z55eSqhXGfd/uo+1o+232cbBDH16NWZiRQAIM6F n7+VTCfPSw== ARC-Authentication-Results: i=1; tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC did not pass); dkim=none (no signatures found); dmarc=none policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=telka.sk; iprev=pass smtp.remote-ip=185.14.234.118 (tortuga.telka.sk); spf=pass smtp.mailfrom=marcel@telka.sk smtp.helo=tortuga.telka.sk; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=tortuga.telka.sk policy.ptr=tortuga.telka.sk; x-return-mx=pass header.domain=telka.sk policy.is_org=yes (MX Records found: tortuga.telka.sk); x-return-mx=pass smtp.domain=telka.sk policy.is_org=yes (MX Records found: tortuga.telka.sk); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=-100 state=0 Authentication-Results: tb-mx1.topicbox.com; arc=none (no signatures found); bimi=skipped (DMARC did not pass); dkim=none (no signatures found); dmarc=none policy.published-domain-policy=none policy.applied-disposition=none policy.evaluated-disposition=none (p=none,d=none,d.eval=none) policy.policy-from=p header.from=telka.sk; iprev=pass smtp.remote-ip=185.14.234.118 (tortuga.telka.sk); spf=pass smtp.mailfrom=marcel@telka.sk smtp.helo=tortuga.telka.sk; x-aligned-from=pass (Address match); x-me-sender=none; x-ptr=pass smtp.helo=tortuga.telka.sk policy.ptr=tortuga.telka.sk; x-return-mx=pass header.domain=telka.sk policy.is_org=yes (MX Records found: tortuga.telka.sk); x-return-mx=pass smtp.domain=telka.sk policy.is_org=yes (MX Records found: tortuga.telka.sk); x-tls=pass smtp.version=TLSv1.2 smtp.cipher=ECDHE-RSA-AES256-GCM-SHA384 smtp.bits=256/256; x-vs=clean score=-100 state=0 X-ME-VSCause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeltddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvffukfhfgggtuggjsehmtderredttddvnecu hfhrohhmpeforghrtggvlhcuvfgvlhhkrgcuoehmrghrtggvlhesthgvlhhkrgdrshhkqe enucggtffrrghtthgvrhhnpeekiefhgfekjeevudfhteelvefgveeffeejuedugedtleef ieehveeuvdeuheejheenucffohhmrghinhepihhllhhumhhoshdrohhrghdpthgvlhhkrg drshhknecukfhppedukeehrddugedrvdefgedruddukeenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepihhnvghtpedukeehrddugedrvdefgedruddukedphhgvlhhope htohhrthhughgrrdhtvghlkhgrrdhskhdpmhgrihhlfhhrohhmpeeomhgrrhgtvghlseht vghlkhgrrdhskheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepoeguvghvvghloh hpvghrsehlihhsthhsrdhilhhluhhmohhsrdhorhhgqe X-ME-VSScore: -100 X-ME-VSCategory: clean Received-SPF: pass (telka.sk: 185.14.234.118 is authorized to use 'marcel@telka.sk' in 'mfrom' identity (mechanism 'ip4:185.14.234.118' matched)) receiver=tb-mx1.topicbox.com; identity=mailfrom; envelope-from="marcel@telka.sk"; helo=tortuga.telka.sk; client-ip=185.14.234.118 Received: from tortuga.telka.sk (tortuga.telka.sk [185.14.234.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tb-mx1.topicbox.com (Postfix) with ESMTPS for ; Sun, 2 Jun 2024 05:05:48 -0400 (EDT) (envelope-from marcel@telka.sk) Received: (qmail 32154 invoked from network); 2 Jun 2024 09:05:41 -0000 Received: from telcontar.in.telka.sk (HELO telcontar) (marcel@10.0.0.10) by tortuga.telka.sk with ESMTPSA (DHE-RSA-AES256-GCM-SHA384 encrypted); 2 Jun 2024 09:05:41 -0000 Date: Sun, 2 Jun 2024 11:05:40 +0200 From: Marcel Telka To: illumos-developer Subject: Re: [developer] Raw ethernet packets Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="+jU0QXCv7MrAqw+o" Content-Disposition: inline In-Reply-To: Topicbox-Policy-Reasoning: allow: sender is a member Topicbox-Message-UUID: 53e9be10-20bf-11ef-a743-99394093195e --+jU0QXCv7MrAqw+o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, May 31, 2024 at 10:43:03AM +0200, Marcel Telka wrote: > I'm trying to send a raw ethernet packet from an userland application > but all my attempts so far were unsuccessful. I basically tried two Attached is the testing program ethersend.c that uses both bpf and socket approaches to send the raw ethernet frame. In both cases the frame is silently dropped in mac_tx() because fe_tx_srs is NULL: https://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/io/mac/mac_client.c?r=119d61cc&mo=100885&fi=3519#3576 There is attached the ethersend.d dtrace script that shows the issue: # gcc -Wall -lsocket -o ethersend ethersend.c # ./ethersend.d -c './ethersend e1000g0' 2>&1 | grep mac_tx 1 -> mac_tx 1 | mac_tx:entry 0 1 <- mac_tx 0 1 -> mac_tx 1 | mac_tx:entry 0 1 <- mac_tx 0 # Since something similar reportedly works on dilos (I assume it is a fork of old illumos-gate) then it looks like the issue is in new illumos. I'll try to do some archaeology... -- +-------------------------------------------+ | Marcel Telka e-mail: marcel@telka.sk | | homepage: http://telka.sk/ | +-------------------------------------------+ --+jU0QXCv7MrAqw+o Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ethersend.c" #include #include #include #include #include #include #include #include #include #include #include char packet[] = "\xff\xff\xff\xff\xff\xff" "\x00\x1c\x25\xa0\xb7\x2e" "\x08\x06\x00\x01" "\x08\x00\x06\x04\x00\x01" "\x00\x1c\x25\xa0\xb7\x2e" "\x0a\x00\x00\x0d" "\xff\xff\xff\xff\xff\xff" "\x0a\x00\x00\x3d" "\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00" ; int send_bpf(const char *iface, char *data, size_t len) { int fd = open("/dev/bpf", O_RDWR); if (fd < 0) { perror("open"); return -1; } struct ifreq ifr; (void) memset(&ifr, 0, sizeof ifr); (void) memcpy(&ifr.ifr_name, iface, strlen(iface)); if (ioctl(fd, BIOCSETIF, &ifr) < 0) { perror("BIOCSETIF"); return -2; } int enable; enable = 1; if (ioctl(fd, BIOCIMMEDIATE, &enable) < 0) { perror("BIOCIMMEDIATE"); return -3; } enable = 1; if (ioctl(fd, BIOCSHDRCMPLT, &enable) < 0) { perror("BIOCSHDRCMPLT"); return -4; } size_t ret = write(fd, data, len); if (ret >= 0) printf("send_bpf sent %ld bytes\n", ret); if (ret != len) { fprintf(stderr, "write returned %ld, expected %ld\n", ret, len); return -5; } if (close(fd) < 0) { perror("close"); return -6; } return 0; } int send_socket(const char *iface, char *data, size_t len) { int s = socket(AF_PACKET, SOCK_RAW, 0); if (s < 0) { perror("socket"); return -1; } struct ifreq ifr; (void) memset(&ifr, 0, sizeof ifr); (void) memcpy(&ifr.ifr_name, iface, strlen(iface)); if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { perror("SIOCGIFINDEX"); return -2; } struct sockaddr_ll lls; (void) memset(&lls, 0, sizeof lls); lls.sll_family = AF_PACKET; lls.sll_protocol = 0; lls.sll_ifindex = ifr.ifr_index; if (bind(s, (struct sockaddr *)&lls, sizeof lls) < 0) { perror("bind"); return -3; } size_t ret = send(s, data, len, 0); if (ret >= 0) printf("send_socket sent %ld bytes\n", ret); if (ret != len) { fprintf(stderr, "send returned %ld, expected %ld\n", ret, len); return -4; } if (close(s) < 0) { perror("close"); return -5; } return 0; } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Missing interface\n"); return 1; } int ret; ret = send_bpf(argv[1], packet, sizeof packet - 1); if (ret != 0) fprintf(stderr, "send_bpf: %d\n", ret); ret = send_socket(argv[1], packet, sizeof packet - 1); if (ret != 0) fprintf(stderr, "send_socket: %d\n", ret); return 0; } --+jU0QXCv7MrAqw+o Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ethersend.d" #!/usr/sbin/dtrace -s #pragma D option flowindent fbt::send:entry { self->t = 1; } fbt::write:entry /execname == "ethersend" && arg0 > 2/ { self->t = 1; } fbt:::entry /self->t/ { } fbt:::return /self->t/ { trace(arg1); } mac_tx:entry /self->t/ { trace(((mac_client_impl_t *)arg0)->mci_flent->fe_tx_srs); } fbt::send:return { self->t = 0; } fbt::write:return { self->t = 0; } --+jU0QXCv7MrAqw+o--