akaros/kern/src/net/pktmedium.c
<<
>>
Prefs
   1/* Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
   2 * Portions Copyright © 1997-1999 Vita Nuova Limited
   3 * Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
   4 *                                (www.vitanuova.com)
   5 * Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
   6 *
   7 * Modified for the Akaros operating system:
   8 * Copyright (c) 2013-2014 The Regents of the University of California
   9 * Copyright (c) 2013-2015 Google Inc.
  10 *
  11 * Permission is hereby granted, free of charge, to any person obtaining a copy
  12 * of this software and associated documentation files (the "Software"), to deal
  13 * in the Software without restriction, including without limitation the rights
  14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15 * copies of the Software, and to permit persons to whom the Software is
  16 * furnished to do so, subject to the following conditions:
  17 *
  18 * The above copyright notice and this permission notice shall be included in
  19 * all copies or substantial portions of the Software.
  20 *
  21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27 * SOFTWARE. */
  28
  29#include <slab.h>
  30#include <kmalloc.h>
  31#include <kref.h>
  32#include <string.h>
  33#include <stdio.h>
  34#include <assert.h>
  35#include <error.h>
  36#include <cpio.h>
  37#include <pmap.h>
  38#include <smp.h>
  39#include <net/ip.h>
  40
  41static void pktbind(struct Ipifc *i, int unused_int, char **unused_char_pp_t);
  42static void pktunbind(struct Ipifc *i);
  43static void pktbwrite(struct Ipifc *i, struct block *, int unused_int,
  44                      uint8_t *unused_uint8_p_t);
  45static void pktin(struct Fs *f, struct Ipifc *i, struct block *b);
  46
  47struct medium pktmedium = {
  48        .name = "pkt",
  49        .hsize = 14,
  50        .mintu = 40,
  51        .maxtu = 4 * 1024,
  52        .maclen = 6,
  53        .bind = pktbind,
  54        .unbind = pktunbind,
  55        .bwrite = pktbwrite,
  56        .pktin = pktin,
  57        .unbindonclose = 1,
  58};
  59
  60/*
  61 *  called to bind an IP ifc to an ethernet device
  62 *  called with ifc wlock'd
  63 */
  64static void pktbind(struct Ipifc *i, int unused_int, char **unused_char_pp_t)
  65{
  66}
  67
  68/*
  69 *  called with ifc wlock'd
  70 */
  71static void pktunbind(struct Ipifc *i)
  72{
  73}
  74
  75/*
  76 *  called by ipoput with a single packet to write
  77 */
  78static void
  79pktbwrite(struct Ipifc *ifc, struct block *bp, int unused_int,
  80                  uint8_t * unused_uint8_p_t)
  81{
  82        /* enqueue onto the conversation's rq */
  83        bp = concatblock(bp);
  84        ptclcsum_finalize(bp, 0);
  85        ipifc_trace_block(ifc, bp);
  86        qpass(ifc->conv->rq, bp);
  87}
  88
  89/*
  90 *  called with ifc rlocked when someone write's to 'data'
  91 */
  92static void pktin(struct Fs *f, struct Ipifc *ifc, struct block *bp)
  93{
  94        if (ifc->lifc == NULL) {
  95                freeb(bp);
  96        } else {
  97                ipifc_trace_block(ifc, bp);
  98                ipiput4(f, ifc, bp);
  99        }
 100}
 101
 102void pktmediumlink(void)
 103{
 104        addipmedium(&pktmedium);
 105}
 106