_      _            _
         _ __ ___ (_) ___| | __  _ __ | |
        | '_ ` _ \| |/ _ \ |/ / | '_ \| |
        | | | | | | |  __/   < _| | | | |
        |_| |_| |_| |\___|_|\_(_)_| |_|_|
                  | |
                  |_|       Thoughts on (technical) stuff...
You're from: 54.226.5.29

June 2012 Archives

Jun 27 2012

Sync subversion to github.com

Posted in programming; by Miek Gieben; comments: 0

This is a post that details on how to sync a subversion repository to git repository on github.com, and how to keep it in sync.

The following sites were instrumental in getting this to work:

There are a number of steps to take. From a bird's eye view:

  1. Use git svn to clone the svn repo to a git repo;
  2. Create a github git repo;
  3. Add a remote origin in your local git to the remote github repo;
  4. Use some SSH foo to use a separate SSH key for pushing to github.com.

Prerequisites

  • We are working with the fictional svn repo located at https://svn.example.net/example;
  • git-svn is installed;
  • ssh is installed.

Clone the repository

mkdir github.com
cd github.com
git svn clone -s https://svn.example.net/example

Create github repo

Go to the github.com's website and create a new repository, in this case we'll use my username (miekg). So the github.com's repository is:

github.com:miekg/example.git

Add a remote in (local) git

git remote add origin git@github.com:miekg/example.git

And push the contents to the remote (i.e. github):

git push origin master

And voila. You have a git repository from a cloned svn repository.

Keeping it in sync

Ideally you want to run a cronjob to keep this repository in sync with the subversion repository. The git commands used are trivial:

git svn rebase
git push

However the ssh key you're using has a passphrase. An idea is to use a separate key (without a passphrase) just for this repository. Sadly it is not possible to restrict a ssh key to a specific repository, so this new, passphrase-less key can be used to update all your repositories.

But still this can be useful, so how do you set this up?

  1. First create a new key pair: ssh-keygen -f github.com.
  2. Create a Host-stanza in ~/.ssh/config:

    Host example.github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/github.com
  3. Use the "fake" host (example.github.com) as the remote branch in git:

    git remote add origin example.github.com:miekg/example.git

    If you already added the remote you can just edit .git/config and make the change there.

  4. Any git push will now use the ssh-server example.github.com, the user git and the identity file ~/.ssh/github.com and will not prompt for a passphrase.

Dealing with changes/patches

The hard part is getting changes made in this git repository back upstream (in the origin subversion repository). You can do this with git, but it gets complicated (IMHO).

A simpler idea is just to not touch this git repository, but fork it, make your changes there and send the patch to the maintainer of the subversion repository. The git repository then gets synchronized again (hopefully with your changes).


Jun 22 2012

Munin port traffic plugin

Posted in linux, site; by Miek Gieben; comments: 0

I wanted to look at the increase in ntp traffic now that I've joined the pool.ntp.org ranks. Unfortunately munin didn't have a watch-port-x-and-draw-something-plugin. So I wrote my own based upon the ip_ plugin.

The plugin monitors both v6, v4, tcp and udp and plots them together, as send and received. Just symlink the port number to the plugin:

ip_port_123 -> ip_port_

For it to work, you do need some iptables rules, so yes, this plugin only works in Linux. See the munin plugin for the documentation.

Obligatory screenshot:


Jun 21 2012

Printing MX records with Go DNS

Posted in go, dns(sec); by Miek Gieben; comments: 0

Now that the API seems to stabilize it is time to update these items.

We want to create a little program that prints out the MX records of domains, like so:

% mx miek.nl
miek.nl.        86400   IN      MX      10 elektron.atoom.net.

Or

% mx microsoft.com 
microsoft.com.  3600    IN      MX      10 mail.messaging.microsoft.com.

We are using my Go DNS package. First the normal header of a Go program, with a bunch of imports. We need the dns package:

package main

import (
    "dns"
    "os"
    "fmt"
)

Next we need to get the local nameserver to use:

config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")

Then we create a dns.Client to perform the queries for us. In Go:

c := new(dns.Client)

We skip some error handling and assume a zone name is given. So we prepare our question. For that to work, we need:

  1. a new packet (dns.Msg);
  2. setting some header bits (dns.Msg.MsgHdr);
  3. define a question section;
  4. fill out the question section: os.Args[1] contains the zone name.

Which translates into:

m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(os.Args[1], dns.TypeMX)
m.MsgHdr.RecursionDesired = true

Then we need to finally 'ask' the question. We do this by calling the Exchange() function.

r, err := c.Exchange(m, config.Servers[0]+":"+config.Port)

Check if we got something sane. The following code snippet prints the answer section of the received packet:

if r != nil {
        if r.Rcode != dns.RcodeSuccess {
                fmt.Printf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1])
                os.Exit(1)
        }
        // Stuff must be in the answer section
        for _, a := range r.Answer {
                fmt.Printf("%v\n", a)
        }
} else {
        fmt.Printf("*** error: %s\n", err.String())
}

And we are done.

Full source

The full source of mx.go can be found over at github. Compiling works with go build.


Jun 19 2012

ath9k under Linux

Posted in linux; by Miek Gieben; comments: 0

For some reason I was experiencing wifi disconnects with the ath9k wifi driver under Linux (Ubuntu 12.04). After reading numerous blogs and bug reports (disable ipv6, use hwcrypto=0, etc.), I suspected it was the power management that was somehow disabling the driver, in turn leading to a disconnect. This will probably be fixed in newer kernels (Ubuntu 12.04 ships 3.2.x).

For now I took a shortcut and disabled the power management on the wlan0 interface. For this to work I created a (super)small script: /etc/network/if-up.d/wifipower:

#!/bin/sh -e
case $IFACE in
    wlan0) /sbin/iwconfig "$IFACE" power off ;;
esac

Jun 19 2012

pandoc test

Posted in site; by Miek Gieben; comments: 0

A little test to see if pandoc will convert this to (good) html.

Yes works :)

  • this
  • is
  • a
  • list
  1. this
  2. is
  3. a
  4. numbered list

Table test

Reference conversions from Pandoc to "xml2rfc".
Pandoc Converts to Type
[Click](URL) <eref target="URL">Click... External
[See](#local) <xref target="local">See... Internal
[](#RFC2119) <xref target="RFC2119"/> Citation

Jun 14 2012

IPv6

Posted in site; by Miek Gieben; comments: 4

Deployed IPv6 on my internal network of Linux machines. These machines work with network-manager, dnsmasq and resolvconf. The moral of getting IPv6 to work: radvd on the server, dhcpv6 didn't work for me.

If you want static IPv6 addresses you must disable the IPv6 privacy extensions from within network-manager otherwise it won't work. In my case I had to edit: /etc/NetworkManager/system-connections/Wired\ connection\ 1 and changed:

[ipv6]
method=auto

To:

[ipv6]
method=auto
ip6-privacy=0

Settings from sysctl will be overruled... took me a while to find this.


Jun 14 2012

80s-terminal-look

Posted in site; by Miek Gieben; comments: 0

Totally ripped off xip.io's theme for this blog.

Kinda of like the 80s-terminal-look.


Jun 04 2012

draft-gieben-creating-rfcs-pandoc-00.txt

Posted in pandoc; by Miek Gieben; comments: 0

Maybe I'll try to send it in as a individual submission.

+-

  Network Working Group                                          R. Gieben
  Internet-Draft                                                      SIDN
  Intended status: Informational                                April 2012
  Expires: October 3, 2012


               Creating Internet Drafts and RFCs using Pandoc
                    draft-gieben-creating-rfcs-pandoc-00

  Abstract

     This memo presents a technique for using Pandoc syntax as a source
     format for documents in the Internet-Drafts (I-Ds) and Request for
     Comments (RFC) series.

     Using Pandoc syntax this way minimizes the need to directly edit the
     raw XML, but it does not completely make the XML invisible.

  Status of this Memo

     This document is an Internet-Draft and is NOT offered in accordance
     with Section 10 of RFC 2026, and the author does not provide the IETF
     with any rights other than to publish as an Internet-Draft.

     Internet-Drafts are working documents of the Internet Engineering
     Task Force (IETF).  Note that other groups may also distribute
     working documents as Internet-Drafts.  The list of current Internet-
     Drafts is at http://datatracker.ietf.org/drafts/current/.

     Internet-Drafts are draft documents valid for a maximum of six months
     and may be updated, replaced, or obsoleted by other documents at any
     time.  It is inappropriate to use Internet-Drafts as reference
     material or to cite them other than as "work in progress."

     This Internet-Draft will expire on October 3, 2012.
















  Gieben                   Expires October 3, 2012                [Page 1]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


  Table of Contents

     1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . . . 3
     2.  Using Pandoc for RFC creation . . . . . . . . . . . . . . . . . 4
     3.  Syntax  . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
       3.1.  References  . . . . . . . . . . . . . . . . . . . . . . . . 7
     4.  Security Considerations . . . . . . . . . . . . . . . . . . . . 8
     5.  IANA Considerations . . . . . . . . . . . . . . . . . . . . . . 8
     6.  Acknowledgements  . . . . . . . . . . . . . . . . . . . . . . . 8
     7.  Normative References  . . . . . . . . . . . . . . . . . . . . . 8
     Author's Address  . . . . . . . . . . . . . . . . . . . . . . . . . 9








































  Gieben                   Expires October 3, 2012                [Page 2]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


  1.  Introduction

     This memo presents a technique for using Pandoc [1] syntax as a
     source format for documents in the Internet-Drafts (I-Ds) and Request
     for Comments (RFC) series.

     Pandoc is an "almost plain text" format, which is inspired by
     Markdown Syntax [2] and therefor particularly well suited for editing
     RFC-like documents.

     The power of Pandoc also comes from the fact that it can be
     translated to numerous output formats, including, but not limited to:
     HTML, Markdown and "docbook" XML.

     In this case the Pandoc sources are converted to "docbook" XML.  This
     XML is then converted again, using an XSLT stylesheet, to XML
     suitable as input for "xml2rfc" [RFC2629].  The conversions are
     collectively called Pandoc2rfc [pandoc2rfc].

     Pandoc2rfc is in some way amusing, as we start off with (almost)
     plain text, use elaborate XML and end up with plain text again, as
     shown in Figure 1.

                        Attempt to justify Pandoc2rfc.

          +-------------------+   Pandoc   +---------+
          | ALMOST PLAIN TEXT |   ------>  | DOCBOOK |
          +-------------------+            +---------+
                        |                       |
          non-existent  |                       | XSLT (transform.xsl)
           quicker way  |                       |
                        v                       v
                +------------+    xml2rfc  +---------+
                | PLAIN TEXT |  <--------  | XML2RFC |
                +------------+             +---------+

                                   Figure 1

     For the conversion to work the following tools and files need to be
     installed:

     o  xml2rfc [3];

     o  xsltproc [4] (or any other XSLT (v1) processor);

     o  Pandoc [1];





  Gieben                   Expires October 3, 2012                [Page 3]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


     o  transform.xsl [5].


  2.  Using Pandoc for RFC creation

     As said in the introduction the use of Pandoc does not eliminate the
     need to setup some files in XML.  Particularly the "<front>" matter
     of "xml2rfc" can not be codified in Pandoc, so a template like this
     is still needed:

                            A minimal template.xml.

       < ?xml version='1.0' ?>
       <!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>

       <rfc ipr='trust200902' docName='draft-gieben-pandoc-rfcs-01'>
        <front>
           <title>Creating Internet Drafts and RFCs using Pandoc</title>
           <abstract>
               < ?rfc include="abstract.xml"?>
           </abstract>

           <author initials="R." surname="Gieben"
               fullname="R. (Miek) Gieben">
               <organization>SIDN</organization>
           </author>

       </front>

       <middle>
           < ?rfc include="middle.xml"?>
       </middle>

       <back>
           <references title="Normative References">
               < ?rfc include="reference.RFC.2629.xml"?>
           </references>
           < ?rfc include="back.xml"?>
       </back>
       </rfc>

                                   Figure 2

     The template shown in Figure 2 includes 3 (not counting the
     reference) XML files:






  Gieben                   Expires October 3, 2012                [Page 4]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


     1.  abstract.xml;

     2.  middle.xml;

     3.  back.xml.

     To create the complete document you will need to edit three Pandoc
     files and the template, (".pdc" is the extension for Pandoc files):

     1.  abtract.pdc;

     2.  middle.pdc;

     3.  back.pdc;

     4.  template.xml (probably a fairly static file once setup).

     To convert, for instance, the "middle.pdc" file to XML the following
     command is executed on a Unix-like system:

     pandoc -t docbook -s middle.pdc|xsltproc transform.xsl - > middle.xml

     This is also done for "abstract.pdc" and "back.pdc".  After which
     "xml2rfc" is called:

     xml2rfc template.xml draft.txt

     Which creates the final output.  Of course this process can be
     automated using a tool like "make".

     When using Pandoc2rfc consider adding the following sentence to an
     Acknowledgements section:

     This document was prepared using Pandoc2rfc.


  3.  Syntax

     Almost all features of "xml2rfc" are supported.  A notable exception
     is the "crefs" tag, but HTML comments are allowed within Pandoc
     sources so they may be used as a substitute.

     Sections are started by using a header [README#headers].

     Paragraphs are separated by an empty line.  Hanging paragraphs are
     entered by using a definition list [README#deflists].

     Footnotes are not supported.  Pandoc2rfc (ab)uses the footnote syntax



  Gieben                   Expires October 3, 2012                [Page 5]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


     to support indices.  Block quotes are not directly supported in
     "xml2rfc" so they get translated to a hanging paragraph.

     A good number of different type of lists are supported, they are
     translated according to the following table.

                  List conversions from Pandoc to "xml2rfc".

      +---------------------------------+------------------------------+
      | Pandoc                          | Converts to                  |
      +---------------------------------+------------------------------+
      | "* First item"                  | "<list style="symbol">"      |
      | "1. First item"                 | "<list style="numbers">"     |
      | "#. First item"                 | "<list style="empty">"       |
      | "a. First item"                 | "<list style="letters">"     |
      | "A. First item"                 | "list style="format %C.">"   |
      | "i. First item"                 | "<list style="format %i.">"  |
      | "I. First item"                 | "<list style="format (%d)">" |
      +---------------------------------+------------------------------+

                                    Table 1

     A figure or artwork is created with a paragraph that is indented with
     four spaces [README#codeblocks].  A figure caption is always
     translated to a "<preamble>".  A figure caption is created by using
     this text as the last line in the artwork: "Figure: ...caption
     text..."

     The different tables [README#tables] Pandoc supports are all mapped
     to "<texttable>".  A table caption is always translated to a
     "<postamble>".  A table caption is added by using "Table: ...caption
     text..." after a table.

     The caption is _always_ translated to a "<preamble>".  The
     "<postamble>" tag isn't supported.  If a table has a caption, it will
     *also* get a reference.  See Section 3.1 for the details.

     As footnotes are not supported in RFCs the syntax in Pandoc is used
     to support an index.  Footnotes in Pandoc (and thus an index in the
     RFC) are entered in two steps, you have a marker in the text, and
     later you give actual footnote text.  Like this:

     [^1]

     [^1]: footnote text

     This text translates to: "<iref item="footnote text"/>".  It points
     to the page where to footnote marker was placed.  Sub items are also



  Gieben                   Expires October 3, 2012                [Page 6]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


     supported.  Use an exclamation mark ("!") to separate them: "[^1]:
     item!sub item".

  3.1.  References

     References to section are created automatically by Pandoc and the
     normal Pandoc rules are followed.

                Reference conversions from Pandoc to "xml2rfc".

     +-------------------------+------------------------------+----------+
     | Pandoc                  | Converts to                  | Type     |
     +-------------------------+------------------------------+----------+
     | "[Click](URL)"          | "<eref                       | External |
     |                         | target="URL">Click..."       |          |
     | "[See](#local)"         | "<xref                       | Internal |
     |                         | target="local">See..."       |          |
     | "[](#RFC2119)"          | "<xref target="RFC2119"/>"   | Citation |
     +-------------------------+------------------------------+----------+

                                    Table 2

     Internal references will add "Section:", "Table:" or "Figure:"
     depending on where it points to (this is the default behavior of
     "xml2rfc").  For the citations to work the reference anchor must be
     known (i.e. the RFC reference.xml must be included in the template).

     References to tables and figures are not handled by Pandoc, this
     behavior is implemented in the XSLT stylesheets, therefor the rules
     are slightly different (and less flexible).  A figure and table only
     get a reference when they have a caption.  If a figure has a caption
     it is also centered on the page.

     The reference anchor attribute will be: "fig:" + "first 10
     (normalized) characters from the caption" for figures and "tab:" +
     "first 10 (normalized) characters from the caption" for tables.
     Normalized is:

     o  Take the first 10 characters of the caption (i.e. this is the text
        _after_ the string "Figure:" or "Table:");

     o  Spaces are translated to a minus "-";

     o  Uppercase letters translated to lowercase.

     For example a figure with a caption "Figure: A minimal template" will
     get the anchor "fig:a-minimal-"




  Gieben                   Expires October 3, 2012                [Page 7]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


  4.  Security Considerations

     This memo raises no security issues.


  5.  IANA Considerations

     This memo has no actions for IANA.


  6.  Acknowledgements

     The following people have helped to make Pandoc2rfc what it is today:
     Benno Overeinder, Erlend Hamnaberg, Matthijs Mekking, and Trygve
     Laugstoel.

     This document was prepared using Pandoc2rfc.


  7.  Normative References

     [README#codeblocks]
                MacFarlane, J., "PANDOC Documentation", 2006, <http://
                johnmacfarlane.net/pandoc/
                README.html#indented-code-blocks>.

     [README#deflists]
                MacFarlane, J., "PANDOC Documentation", 2006, <http://
                johnmacfarlane.net/pandoc/README.html#definition-lists>.

     [README#headers]
                MacFarlane, J., "PANDOC Documentation", 2006,
                <http://johnmacfarlane.net/pandoc/README.html#headers>.

     [README#tables]
                MacFarlane, J., "PANDOC Documentation", 2006,
                <http://johnmacfarlane.net/pandoc/README.html#tables>.

     [RFC2629]  Rose, M., "Writing I-Ds and RFCs using XML", RFC 2629,
                June 1999.

     [pandoc2rfc]
                Gieben, R., "Pandoc2rfc", 2012,
                <http://github.com/miekg/pandoc2rfc>.

     [1]  <http://johnmacfarlane.net/pandoc/>

     [2]  <http://daringfireball.net/projects/markdown/>



  Gieben                   Expires October 3, 2012                [Page 8]
  
  Internet-Draft           Pandoc for RFC creation              April 2012


     [3]  <http://xml.resource.org/>

     [4]  <http://xmlsoft.org/xslt/xsltproc2.html>

     [5]  <https://raw.github.com/miekg/pandoc2rfc/master/transform.xsl>


  Author's Address

     R. (Miek) Gieben
     SIDN
     Meander 501
     Arnhem,   6825 MD
     NL

     Phone:
     Email: miek@miek.nl
     URI:   http://miek.nl/

































  Gieben                   Expires October 3, 2012                [Page 9]