<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rohit</title>
    <description>The latest articles on DEV Community by Rohit (@rkj2096).</description>
    <link>https://dev.to/rkj2096</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1932072%2Fa0120e15-9020-46b1-b76f-313c9d20d714.jpg</url>
      <title>DEV Community: Rohit</title>
      <link>https://dev.to/rkj2096</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rkj2096"/>
    <language>en</language>
    <item>
      <title>Committed a Secret to GitHub Repo</title>
      <dc:creator>Rohit</dc:creator>
      <pubDate>Thu, 22 Aug 2024 19:05:29 +0000</pubDate>
      <link>https://dev.to/rkj2096/committed-a-secret-to-github-repo-11a1</link>
      <guid>https://dev.to/rkj2096/committed-a-secret-to-github-repo-11a1</guid>
      <description>&lt;p&gt;Oops, I just committed my API key to GitHub—every developer's rite of passage! If you're a newbie who’s just experienced this, welcome to the club! Don't worry, it happens to the best of us, but now it's time to fix that little slip-up before you start polishing your resume. It happened to me when I started working on my first real project called Tapestry Pooling. I had committed a SendGrid API key to a GitHub repo.&lt;/p&gt;

&lt;p&gt;Step one: Panic. Just kidding—no panicking! What you actually need to do first is ensure that the secret is useless to anyone who might have seen it. If it’s an API key, delete or regenerate it. If it’s a password, change it faster than you can say, "Oh no!"&lt;/p&gt;

&lt;p&gt;Next, it’s time to erase all evidence from the scene of the crime—aka your repo history. The BFG Repo-Cleaner is your new best friend. It’s like a time machine that helps you rewrite history, removing those secrets from your Git history as if they never existed. You can learn how to wield this powerful tool here: &lt;a href="https://rtyley.github.io/bfg-repo-cleaner/" rel="noopener noreferrer"&gt;BFG Repo-Cleaner&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If your code is on GitHub, there's one more thing you need to do. GitHub is like an elephant—it never forgets, especially when it comes to pull request refs. You’ll need to reach out to GitHub support and politely ask them to scrub those PR refs clean. Be nice; they hold the keys to your repo’s past!&lt;/p&gt;

&lt;p&gt;Remember, it's not the mistake that defines you—it's how quickly you can clean up after it &amp;gt;&amp;lt;. And hey, after this, you'll have a great story to share with fellow developers.&lt;/p&gt;

&lt;p&gt;Next may be you want to learn how to handler secrets. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fast Packet IO</title>
      <dc:creator>Rohit</dc:creator>
      <pubDate>Mon, 19 Aug 2024 17:35:23 +0000</pubDate>
      <link>https://dev.to/rkj2096/fast-packet-io-3goh</link>
      <guid>https://dev.to/rkj2096/fast-packet-io-3goh</guid>
      <description>&lt;p&gt;netmap is a framework for fast packet I/O from userspace. Lets first try to understand why do we need it. OS kernel implements TCP/IP stack protocols up to the transport layer. While the applications layer protocols (HTTP, FPT, SSH, SMTP etc) are implemented in userspace. Per packet dynamic memory allocation, system calls overhead and memory allocation make traditional Linux network stack inefficient. netmap tries to solve this problem make the packet data-path efficient.&lt;/p&gt;

&lt;h3&gt;
  
  
  Netmap uses these techniques to get it's high performance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;a lightweight metadata representation, processing
of large number of packets in each system call, thus
amortizing its cost;&lt;/li&gt;
&lt;li&gt;preallocated, linear, fixed size packet buffers&lt;/li&gt;
&lt;li&gt;removal of data-copy costs by granting applications
direct, protected access to the packet buffers
of packets between interfaces;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Netmap API
&lt;/h3&gt;

&lt;p&gt;netmap has been implemented as kernel module for FreeBSD and Linux. &lt;br&gt;
&lt;code&gt;ioctl(.., NIOCREG, arg)&lt;/code&gt;&lt;br&gt;
The argument contains the interface name, and optionally the indication of which rings&lt;br&gt;
we want to control through this file descriptor. &lt;/p&gt;

&lt;h3&gt;
  
  
  Other fast packet I/O solutions
&lt;/h3&gt;

&lt;p&gt;XDP(express data path) is an high-performance data-path used to send and receive packets by bypassing os kernel networking stack. It uses e-BPF(extended Berkeley Packet Filter), it is an in-kernel virtual machine, ability to run user-supplied program inside kernel. In short, e-BPF allows us to safely extends the functionalities of kernel without changing the kernel source code or loading kernel module&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://linux-kernel-labs.github.io/refs/heads/master/labs/networking.html#overview" rel="noopener noreferrer"&gt;https://linux-kernel-labs.github.io/refs/heads/master/labs/networking.html#overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cs.cornell.edu/%7Eragarwal/pubs/network-stack.pdf" rel="noopener noreferrer"&gt;https://www.cs.cornell.edu/~ragarwal/pubs/network-stack.pdf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/luigirizzo/netmap" rel="noopener noreferrer"&gt;https://github.com/luigirizzo/netmap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ebpf.io/what-is-ebpf/" rel="noopener noreferrer"&gt;https://ebpf.io/what-is-ebpf/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lwn.net/Articles/740157/" rel="noopener noreferrer"&gt;https://lwn.net/Articles/740157/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>netmap</category>
      <category>xdp</category>
      <category>networking</category>
      <category>ebpf</category>
    </item>
    <item>
      <title>chroot system call</title>
      <dc:creator>Rohit</dc:creator>
      <pubDate>Sun, 18 Aug 2024 13:28:14 +0000</pubDate>
      <link>https://dev.to/rkj2096/chroot-system-call-2dfn</link>
      <guid>https://dev.to/rkj2096/chroot-system-call-2dfn</guid>
      <description>&lt;p&gt;While doing a literature survey on Serverless architecture also known as Function-as-a-Service(FaaS). It is yet another type of cloud service provided by public cloud service providers such as AWS (lambda), GCP(Google function) and AWS(Azure functions). &lt;/p&gt;

&lt;p&gt;I came across chroot system call while reading this paper &lt;code&gt;SOCK: Rapid Task Provisioning with Serverless-Optimized Containers&lt;/code&gt; by Edward Oakes et al. It has proposed lightweight isolation as opposed to namespace isolation to solve the problem of &lt;code&gt;coldstart&lt;/code&gt; (this is another topic may be will discuss in a seperate blog). A part of solution is to use chroot (latency &amp;lt; 1μs) to provide isolation as instead to namespace isolation (IPC and mount namespace latency &amp;gt; 10ms). At the time though I was aware of chroot syscall but I didn't know how it works under the hood. So, I started looking into the implementation of chroot and it's working.&lt;/p&gt;

&lt;h2&gt;
  
  
  what is chroot?
&lt;/h2&gt;

&lt;p&gt;chroot changes the apparent root directory for a process and its children. It creates an isolated environment, often used for testing, development, or containing potentially untrusted programs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Change root directory&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chroot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/isolate-dir"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;perror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"chroot"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Change to the new root directory&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;perror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"chdir"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Execute a new shell&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;shell&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"/bin/bash"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="n"&gt;execvp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// If execvp returns, an error occurred&lt;/span&gt;
    &lt;span class="n"&gt;perror&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"execvp"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EXIT_FAILURE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  how it works ?
&lt;/h1&gt;

&lt;p&gt;The chroot is implemented in the Linux kernel source code in the file &lt;code&gt;fs/open.c&lt;/code&gt;. You can look it on the github linuc repository. Let's dive into it's working&lt;/p&gt;

&lt;p&gt;So there is &lt;code&gt;struct fs_struct&lt;/code&gt;, a data structure in the Linux kernel that holds the filesystem-related &lt;code&gt;context&lt;/code&gt; of a process. This includes information such as the current working directory, the root directory, and the umask. &lt;strong&gt;Each process in the kernel has a pointer to an fs_struct, which encapsulates this context&lt;/strong&gt;. The chroot syscall bsically update the root directory of the process by changing this fs_struct inside task_struct. That's it, it's as simple as that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;fs_struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;spinlock_t&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// Protects the structure&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="c1"&gt;// Reference count&lt;/span&gt;
    &lt;span class="n"&gt;seqcount_t&lt;/span&gt; &lt;span class="n"&gt;seq&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;              &lt;span class="c1"&gt;// Sequence counter for path walking&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;// Root directory&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="n"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;             &lt;span class="c1"&gt;// Current working directory&lt;/span&gt;
    &lt;span class="n"&gt;umode_t&lt;/span&gt; &lt;span class="n"&gt;umask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;// File creation mode mask&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;task_struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Process state&lt;/span&gt;
    &lt;span class="k"&gt;volatile&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// Current state of the process (running, sleeping, etc.)&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                  &lt;span class="c1"&gt;// Process kernel stack&lt;/span&gt;

    &lt;span class="c1"&gt;// Scheduling information&lt;/span&gt;
    &lt;span class="n"&gt;pid_t&lt;/span&gt; &lt;span class="n"&gt;pid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                    &lt;span class="c1"&gt;// Process ID&lt;/span&gt;
    &lt;span class="n"&gt;pid_t&lt;/span&gt; &lt;span class="n"&gt;tgid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="c1"&gt;// Thread group ID&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;task_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// Pointer to the parent process&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;list_head&lt;/span&gt; &lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// List of child processes&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;list_head&lt;/span&gt; &lt;span class="n"&gt;sibling&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;     &lt;span class="c1"&gt;// List of sibling processes&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;list_head&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// List of all processes&lt;/span&gt;

    &lt;span class="c1"&gt;// Memory management&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;mm_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;         &lt;span class="c1"&gt;// Address space of this process&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;mm_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;active_mm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Active address space&lt;/span&gt;

    &lt;span class="c1"&gt;// File system&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;fs_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;         &lt;span class="c1"&gt;// Filesystem information&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;files_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// Open file descriptors&lt;/span&gt;

    &lt;span class="c1"&gt;// Signal handling&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;signal_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Shared signal handlers&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;sighand_struct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sighand&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="c1"&gt;// Signal handlers&lt;/span&gt;

    &lt;span class="c1"&gt;// Timers&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;list_head&lt;/span&gt; &lt;span class="n"&gt;cpu_timers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// CPU-specific timers&lt;/span&gt;

    &lt;span class="c1"&gt;// Debugging&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           &lt;span class="c1"&gt;// Various flags (e.g., for debugging)&lt;/span&gt;
    &lt;span class="kt"&gt;unsigned&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ptrace&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// Ptrace flags&lt;/span&gt;

    &lt;span class="c1"&gt;// More fields...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>os</category>
      <category>syscall</category>
      <category>chroot</category>
    </item>
  </channel>
</rss>
