Changeset 4f64a523 in mainline


Ignore:
Timestamp:
2012-02-12T19:36:32Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
df15e5f
Parents:
1493811
Message:

Need to limit iplink to a single client connection.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/iplink_srv.c

    r1493811 r4f64a523  
    4141#include <inet/iplink_srv.h>
    4242
    43 static void iplink_get_mtu_srv(iplink_conn_t *conn, ipc_callid_t callid,
     43static void iplink_get_mtu_srv(iplink_srv_t *srv, ipc_callid_t callid,
    4444    ipc_call_t *call)
    4545{
     
    4747        size_t mtu;
    4848
    49         rc = conn->srv->ops->get_mtu(conn, &mtu);
     49        rc = srv->ops->get_mtu(srv, &mtu);
    5050        async_answer_1(callid, rc, mtu);
    5151}
    5252
    53 static void iplink_send_srv(iplink_conn_t *conn, ipc_callid_t callid,
     53static void iplink_send_srv(iplink_srv_t *srv, ipc_callid_t callid,
    5454    ipc_call_t *call)
    5555{
     
    6666        }
    6767
    68         rc = conn->srv->ops->send(conn, &sdu);
     68        rc = srv->ops->send(srv, &sdu);
    6969        free(sdu.data);
    7070        async_answer_0(callid, rc);
     71}
     72
     73void iplink_srv_init(iplink_srv_t *srv)
     74{
     75        fibril_mutex_initialize(&srv->lock);
     76        srv->connected = false;
     77        srv->ops = NULL;
     78        srv->arg = NULL;
     79        srv->client_sess = NULL;
    7180}
    7281
     
    7483{
    7584        iplink_srv_t *srv = (iplink_srv_t *)arg;
    76         iplink_conn_t conn;
    7785        int rc;
     86
     87        fibril_mutex_lock(&srv->lock);
     88        if (srv->connected) {
     89                fibril_mutex_unlock(&srv->lock);
     90                async_answer_0(iid, EBUSY);
     91                return EBUSY;
     92        }
     93
     94        srv->connected = true;
     95        fibril_mutex_unlock(&srv->lock);
    7896
    7997        /* Accept the connection */
     
    84102                return ENOMEM;
    85103
    86         conn.srv = srv;
    87         conn.client_sess = sess;
     104        srv->client_sess = sess;
    88105
    89         rc = srv->ops->open(&conn);
     106        rc = srv->ops->open(srv);
    90107        if (rc != EOK)
    91108                return rc;
     
    104121                switch (method) {
    105122                case IPLINK_GET_MTU:
    106                         iplink_get_mtu_srv(&conn, callid, &call);
     123                        iplink_get_mtu_srv(srv, callid, &call);
    107124                        break;
    108125                case IPLINK_SEND:
    109                         iplink_send_srv(&conn, callid, &call);
     126                        iplink_send_srv(srv, callid, &call);
    110127                        break;
    111128                default:
     
    114131        }
    115132
    116         return srv->ops->close(&conn);
     133        return srv->ops->close(srv);
    117134}
    118135
    119 int iplink_ev_recv(iplink_conn_t *conn, iplink_srv_sdu_t *sdu)
     136int iplink_ev_recv(iplink_srv_t *srv, iplink_srv_sdu_t *sdu)
    120137{
    121         async_exch_t *exch = async_exchange_begin(conn->client_sess);
     138        if (srv->client_sess == NULL)
     139                return EIO;
     140
     141        async_exch_t *exch = async_exchange_begin(srv->client_sess);
    122142
    123143        ipc_call_t answer;
  • uspace/lib/c/include/inet/iplink_srv.h

    r1493811 r4f64a523  
    3737
    3838#include <async.h>
     39#include <fibril_synch.h>
     40#include <bool.h>
    3941#include <sys/types.h>
    4042
     
    4244
    4345typedef struct {
     46        fibril_mutex_t lock;
     47        bool connected;
    4448        struct iplink_ops *ops;
    4549        void *arg;
     50        async_sess_t *client_sess;
    4651} iplink_srv_t;
    47 
    48 typedef struct {
    49         iplink_srv_t *srv;
    50         async_sess_t *client_sess;
    51 } iplink_conn_t;
    5252
    5353typedef struct {
     
    6868
    6969typedef struct iplink_ops {
    70         int (*open)(iplink_conn_t *);
    71         int (*close)(iplink_conn_t *);
    72         int (*send)(iplink_conn_t *, iplink_srv_sdu_t *);
    73         int (*get_mtu)(iplink_conn_t *, size_t *);
     70        int (*open)(iplink_srv_t *);
     71        int (*close)(iplink_srv_t *);
     72        int (*send)(iplink_srv_t *, iplink_srv_sdu_t *);
     73        int (*get_mtu)(iplink_srv_t *, size_t *);
    7474} iplink_ops_t;
    7575
     76extern void iplink_srv_init(iplink_srv_t *);
     77
    7678extern int iplink_conn(ipc_callid_t, ipc_call_t *, void *);
    77 extern int iplink_ev_recv(iplink_conn_t *, iplink_srv_sdu_t *);
     79extern int iplink_ev_recv(iplink_srv_t *, iplink_srv_sdu_t *);
    7880
    7981#endif
  • uspace/srv/ethip/ethip.c

    r1493811 r4f64a523  
    5252#define NAME "eth"
    5353
    54 static int ethip_open(iplink_conn_t *conn);
    55 static int ethip_close(iplink_conn_t *conn);
    56 static int ethip_send(iplink_conn_t *conn, iplink_srv_sdu_t *sdu);
    57 static int ethip_get_mtu(iplink_conn_t *conn, size_t *mtu);
     54static int ethip_open(iplink_srv_t *srv);
     55static int ethip_close(iplink_srv_t *srv);
     56static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu);
     57static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu);
    5858
    5959static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    9595        log_msg(LVL_DEBUG, "ethip_iplink_init()");
    9696
     97        iplink_srv_init(&nic->iplink);
    9798        nic->iplink.ops = &ethip_iplink_ops;
    9899        nic->iplink.arg = nic;
     
    148149}
    149150
    150 static int ethip_open(iplink_conn_t *conn)
     151static int ethip_open(iplink_srv_t *srv)
    151152{
    152153        log_msg(LVL_DEBUG, "ethip_open()");
     
    154155}
    155156
    156 static int ethip_close(iplink_conn_t *conn)
    157 {
    158         log_msg(LVL_DEBUG, "ethip_open()");
    159         return EOK;
    160 }
    161 
    162 static int ethip_send(iplink_conn_t *conn, iplink_srv_sdu_t *sdu)
    163 {
    164         ethip_nic_t *nic = (ethip_nic_t *)conn->srv->arg;
     157static int ethip_close(iplink_srv_t *srv)
     158{
     159        log_msg(LVL_DEBUG, "ethip_close()");
     160        return EOK;
     161}
     162
     163static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu)
     164{
     165        ethip_nic_t *nic = (ethip_nic_t *)srv->arg;
    165166        eth_frame_t frame;
    166167        void *data;
     
    188189int ethip_received(iplink_srv_t *srv, void *data, size_t size)
    189190{
     191        log_msg(LVL_DEBUG, "ethip_received(): srv=%p", srv);
     192        ethip_nic_t *nic = (ethip_nic_t *)srv->arg;
    190193        eth_frame_t frame;
    191194        iplink_srv_sdu_t sdu;
    192195        int rc;
    193196
     197        log_msg(LVL_DEBUG, "ethip_received()");
     198
     199        log_msg(LVL_DEBUG, " - eth_pdu_decode");
    194200        rc = eth_pdu_decode(data, size, &frame);
    195         if (rc != EOK)
    196                 return rc;
    197 
     201        if (rc != EOK) {
     202                log_msg(LVL_DEBUG, " - eth_pdu_decode failed");
     203                return rc;
     204        }
     205
     206        log_msg(LVL_DEBUG, " - construct SDU");
     207        sdu.lsrc.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 1;
     208        sdu.ldest.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 4;
    198209        sdu.data = frame.data;
    199210        sdu.size = frame.size;
    200         (void) sdu;
    201         //rc = iplink_ev_recv(conn, &sdu);
     211        log_msg(LVL_DEBUG, " - call iplink_ev_recv");
     212        rc = iplink_ev_recv(&nic->iplink, &sdu);
    202213
    203214        free(frame.data);
     
    205216}
    206217
    207 static int ethip_get_mtu(iplink_conn_t *conn, size_t *mtu)
     218static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu)
    208219{
    209220        log_msg(LVL_DEBUG, "ethip_get_mtu()");
  • uspace/srv/ethip/ethip_nic.c

    r1493811 r4f64a523  
    158158        }
    159159
    160         rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE);
    161         if (rc != EOK) {
    162                 log_msg(LVL_ERROR, "Failed activating NIC '%s'.",
    163                     nic->svc_name);
    164                 goto error;
    165         }
    166 
    167160        log_msg(LVL_DEBUG, "Opened NIC '%s'", nic->svc_name);
    168161        list_append(&nic->nic_list, &ethip_nic_list);
     
    172165        if (rc != EOK)
    173166                goto error;
     167
     168        rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE);
     169        if (rc != EOK) {
     170                log_msg(LVL_ERROR, "Failed activating NIC '%s'.",
     171                    nic->svc_name);
     172                goto error;
     173        }
    174174
    175175        log_msg(LVL_DEBUG, "Initialized IP link service.");
     
    205205        size_t size;
    206206
    207         log_msg(LVL_DEBUG, "ethip_nic_received()");
     207        log_msg(LVL_DEBUG, "ethip_nic_received() nic=%p", nic);
    208208
    209209        rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
     
    213213        }
    214214
     215        log_msg(LVL_DEBUG, "call ethip_received");
    215216        rc = ethip_received(&nic->iplink, data, size);
     217        log_msg(LVL_DEBUG, "free data");
    216218        free(data);
    217219
     
    228230static void ethip_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    229231{
    230         ethip_nic_t *nic;
     232        ethip_nic_t *nic = (ethip_nic_t *)arg;
    231233
    232234        log_msg(LVL_DEBUG, "ethnip_nic_cb_conn()");
Note: See TracChangeset for help on using the changeset viewer.